Why is there no SortedList in Java?
There is no SortedList class in the Java standard library because the List interface already provides a way to store elements in a specific order. The List interface extends the Collection interface, which defines the add() and addAll() methods for adding elements to a list. When adding elements to a list, you can use the add(int index, E element) method to insert the element at a specific position in the list, which allows you to maintain the desired order of the elements.
For example, you can use the following code to create a sorted list in Java:
List<Integer> list = new ArrayList<>();
// add elements to the list in the desired order
list.add(1);
list.add(2);
list.add(3);
// the list is now [1, 2, 3]
Alternatively, you can use the Collections.sort() method to sort a list in ascending order:
List<Integer> list = new ArrayList<>();
list.add(3);
list.add(1);
list.add(2);
// sort the list in ascending order
Collections.sort(list);
// the list is now [1, 2, 3]
Keep in mind that the List interface does not guarantee a specific order for the elements, so you should not rely on the order of the elements unless you have explicitly set it.