So I want to be able to sort this map into a TreeMap or LinkedHashmap by comparing by a value in the CustomObject i.e compare via object.getSomeValue().
So the object with the highest value will be obviously first in the LinkedHashmap
So I want to be able to sort this map into a TreeMap or LinkedHashmap by comparing by a value in the CustomObject i.e compare via object.getSomeValue().
So the object with the highest value will be obviously first in the LinkedHashmap
You can't do it in reasonable manner, but if you really want it what you can do is:
List<EntrySet<UUID, CustomObject>> list = new ArrayList<>(map.entrySet());
Collections.sort(list, (e1, e2) -> /*comparision here*/);
Map<UUID, CustomObject> sortedMap = new LinkedHashMap<>();
for(Entry<UUID, CustomObject> entry: list){
sortedMap.put(entry.getKey(), entry.getValue());
}