This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
HashSet use equals() and hashCode() methods to check the duplicates and follow the natural order.
Hello Matloob, the above statement ia PARTIALLY correct, what I mean is that HashSet makes NO guarantees as to the iteration order of the set; in particular, it does NOT guarantee that the order will remain constant over time.
If you have any doubts, you can consult the API .
And for the purpose of the exams, if you find any questions that ask about the result of a HashSet order, you will find options like "output depends on Hashing" or "Output Not Definded" etc, thats the correct answer, do NOT try to check for ordering. (SAME Applies to numbers AND Strings).
In Your Pursuit Towards Certification, NEVER Give Up.