How do you determine the output of a hash set when it is static? For example the following code will output [Harry, Sam, Jim]
. Why is it printing in this order? Why does the order change when I change Sam`s name?
public static void hashSetTest() {
List<String> names = new ArrayList<>();
names.add("Jack");
names.add("Jim");
names.add("Harry");
names.add("jack");
names.add("Harry");
names.add("Sam");
for(int i =0; i<names.size();i++) {
if(names.get(i).equalsIgnoreCase("jack")) {
names.remove(i);
}
}
Set set = new HashSet();
for(int i =0; i <names.size();i++) {
set.add(names.get(i));
}
System.out.println(set);