For this question, why does it print out [1,2,3] in that specific order since I thought HashSets are not ordered, I would have thought it printed out [1,2,3] in any order. I am aware it gets rid of duplicates. Is it because this question converts from a list -> HashSet -> list?
import java.util.*;
class Try
{
public static void main(String args[]) {
List<Integer> list = new ArrayList<Integer>();
list.add(3);
list.add(3);
list.add(3);
list.add(2);
list.add(2);
list.add(1);
Set<Integer> set = new HashSet<Integer>(list);
List<Integer> list_1 = new ArrayList<Integer>(set);
System.out.println(list_1);
}
}