Concept
How do sorted collections maintain element order?
"The Java Collections framework also provides several sorted data structures. Though an ordered collection such as a List can be sorted by calling the Collections.sort() method, a sorted data structure maintains an ordering. As you add elements to the data structure, they are inserted in the appropriate spot. Such data structures also prevent you from arbitrarily inserting elements in any order. Java defines the SortedSet<T> interface for sorted collections with a TreeSet<T> implementation. As the name implies, the implementation is a balanced binary search tree, in particular a red-black tree. You can construct a TreeSet<T> by providing it a Comparator<T>."
Related Ideas
- What are sorted collections in the Java Collections framework?ComputerScienceOne · Sorted Collections
- How should a Comparator order elements in a SortedSet?ComputerScienceOne · Handling javanull values
- How does a Comparator determine the order of two elements?ComputerScienceOne · Comparators
- How does Java sort arrays and lists with comparators?ComputerScienceOne · Sorted Collections
- What is the difference between Comparable and Comparator in Java?ComputerScienceOne · Comparators
- How can a Comparator sort Student objects by GPA?ComputerScienceOne · Searching
- How do Java sets store unordered unique elements?ComputerScienceOne · Dynamic Data Structures
- How does Java perform binary searches on arrays and lists?ComputerScienceOne · Sorted Collections