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 is a boolean flag in java?
What is scope & storage allocation of static, local and register variables? Explain with an example.
Can a function return a function?
What is an i/o filter?
Define max and min heap, also the search time of heap.
Explain the difference between abstraction and encapsulation.
What is comparable and comparator interface? List their differences
What is extension method in java?
What is import java util arraylist?
what is the messsage u r going to get from an objectoriented programing?
Can you run java program without main method?
What do you mean by local class?
Explain access modifiers in java.
What is the integer of 16?
Give differences between Quicksort &Mergesort. When should these sorts be used andwhat is their running time in java?