Set is just an interface. To retain order, you need to use a specific implementation of that interface and the sub-interface SortedSet, for example, you can use either TreeSet or LinkedHashSet. You can wrap your Set in the following way:
Set myOrderedSet = new LinkedHashSet(mySet);
I recommend this Java course by Intellipaat if you want to learn Java.