Concept
How does Java sort arrays and lists with comparators?
ComputerScienceOne / Sorted Collections
"As with searching, the Arrays and Collections classes provide parameterized sorting methods to sort arrays and Lists. In Java 6 and prior, the implementation was a hybrid merge/insertion sort. Java 7 switched the implementation to Tim Sort. Here too, there are several variations that rely on the natural ordering or allow you to sort a subpart of the collection. The Arrays provides the following method, which sorts arrays of a particular type with a Comparator for that type.\n\npublic static <T> void sort(T[] a, Comparator<T> c)\n\nLikewise, Collections provides the following method.\n\npublic static <T> void sort(List<T> list, Comparator<T> c)\n\nSeveral examples of the usage of these methods are presented in Code Sample"
Related Ideas
- How do the Arrays and Collections classes sort elements?ComputerScienceOne · Sorting
- How can you sort lists and arrays of students in Java?ComputerScienceOne · Handling javanull values
- How does a Comparator determine the order of two elements?ComputerScienceOne · Comparators
- How can a Comparator sort Student objects by GPA?ComputerScienceOne · Searching
- What is the difference between Comparable and Comparator in Java?ComputerScienceOne · Comparators
- How can anonymous classes define custom Java comparators?ComputerScienceOne · Comparators
- How does binary search work with arrays and lists?ComputerScienceOne · Sorting
- How do sorted collections maintain element order?ComputerScienceOne · Sorting