Suppose we hash each
string in String[] strs = {"1", "3", "1", "2"} into a hashset. When I iterate this hashset using a iterator, it always output 3 2 1.
I assume if I run the program in a different platform (eg different JVM, different OS), the output may be 1 2 3, 1 3 2 or 3 1 2 .
So if I am asked this question in the exam, I should say the ouput is unpredictable.
When I worked on the practice exam 4 in OCP
Java SE 6 Programmer Practice Exams , there is a question like this:
give a String[] str = {"1", "3", "1", "2"}, put each of them in a hashset, a linked list, a tree map and a list , what will be the possible output if all of the data structures are iterated.
From my interpretation from the study guide, I cannot predict the output from hashset.
Anyway, my question is will the output be 1 2 3 or 3 2 1 or 2 1 3 or etc depending on the platform your JVM is running.