If set accepts only one argument then how can it compare
two objects to avoid duplicates
Answer Posted / suresh
if the adding element is the first element, then the
element will be added directly to set stream. If there are
elements is Set the first.
1. while adding the new element to set hashcode will be
generated to element by using hashCode() method.
2.Then generated hash code will be compare with each and
every element of the Set by using equels() method. if
equels method retunrs false then the element will be added
to Set else the element will be discarded.
So, in order to avoid the duplicats we have to override
both equels and hash code methods.
If above given info is wrong, plse let me know at
sureshamca47@gmail.com
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What methodology can be employed to locate substrings inside a string?
What is t type java?
What are the disadvantages of using inner classes?
How do you write a scanner class in java?
What is equlas() and hashcode() contract in java? Where does it used?
Is node a data type in java?
Given a singly linked list, determine whether it contains a loop or not without using temporary space?
What is the purpose of using the java bean?
What are the classes of java?
What are functions in java?
Explain differences between collection api and stream api?
What is ctrl m character?
What do you mean by a JVM?
Can finally block be used without a catch?
what is mena by object block any what is the use of that