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 int lol?
Explain about fail fast iterators in java?
what is session in java?
What are the restrictions imposed on method overriding?
Which variables are stored in heap?
Is java type safe?
Enlist diffrent types of inheritance supported by java?
Why we use methods in java?
Does sprintf add a null terminator?
How many types of the indexof method are there for strings?
Draw a UML class diagram for the code fragment given below: public class StringApplet extends Applet { private Label sampleString; private Button showTheString; private ButtonHandler bHandler; private FlowLayout layout; public StringApplet() { sampleString = new Label(" "); showTheString = new Button (" Show the String"); bHandler = new ButtonHandler(); layout = new FlowLayout(); showTheString.addActionListener(bHandler); setLayout(layout); add(sampleString); add(showTheString); } class ButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { samplestring.setText("Good Morning"); } } } Note: The methods need not be indicated on the diagram.
What is difference between fileinputstream and filereader in java?
What exceptions occur during serialization?
What is getkey () in java?
How will you compute size of a structure?