Where do you find Sort( ) methods in Java's library

  • The sort( ) method (an overloaded method) can be found in:

    • java.util.Arrays to sort arrays:

      • sort(int[] a): The sorting algorithm is a Dual-Pivot Quicksort by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch.
      • sort(Object[] a): This implementation is a stable, adaptive, iterative mergesort.

    • java.util.Collections to sort collections (e.g.: ArrayList):

      • According to information on the Internet, they used the Merge Sort in Collections

  • Requirement to use the sort() method(s) in Java's libary:

    • The objects that are sorted must implement the Comparable<T> interface

  • For an example on how to use the sort( ) method in Java's library:

    • See these lecture notes: