Do we have sorted list in java just like SortedSet or TreeMap ? I have a class having one of the property as List of objects. This list has to be sorted at any time when adding or when setting it through setters (set(List list)).
Do we have any component like TreeMap for list ? Any suggestions or help will be really appreciable. Thanks in advance.
The purpose of having a list is that they should maintain the order of the elements in which they were added. So, I believe there is no such
Listimplementation in which the elements are sorted as they are added.You can use
Collections.sort()method to sort the list any time.