For lists, we use the Collections.sort(List) method. What if we want to sort a HashSet?
Based on the answer given by @LazerBanana i will put my own example of a Set sorted by the Id of the Object:
Set yourSet = [...];
yourSet.stream().sorted(new Comparator() {
@Override
public int compare(Clazz o1, Clazz o2) {
return o1.getId().compareTo(o2.getId());
}
}).collect(Collectors.toList()); // Returns the sorted List (using toSet() wont work)