I'm wondering if there is a built-in class in Java that lets me add elements that are automatically sorted. Sorting should preserve add order if two elements are ranked the same. I think it would be like a priority queue but shouldn't "pop" the elements, I want them to stay in the list.
Obviously I could implement this myself but I'd rather use something implemented in the Java language (less bug testing / would be good to know for future projects too instead of importing my own code).
I would also be interested in third party source if there isn't anything like this in the language.
解决方案
It seems SortedList this would work
This class implements a sorted list. It is constructed with a comparator that can compare two objects and sort objects accordingly. When you add an object to the list, it is inserted in the correct place. Object that are equal according to the comparator, will be in the list in the order that they were added to this list. Add only objects that the comparator can compare.