Sorting Algorithm

//The following trivial program prints out its arguments in 
// lexicographic (alphabetical) order:

import java.util.*;

public class Sort {
    public static void main(String[] args) {
        List<String> list = Arrays.asList(args);
  • The sort algorithm reorders a List so that its elements are in ascending order according to an ordering relationship.
  • Two forms of the operation are provided. The simple form takes a List and sorts it according to its elements' natural ordering. The second form of sort takes a Comparator in addition to a List and sorts the elements with the Comparator.
  • The sort operation uses a slightly optimized merge sort algorithm that is fast (it is guaranteed to run in n log(n) time and runs substantially faster on nearly sorted lists) and stable (it doesn't reorder equal elements).

Sorting Algorithm — Structure map

Clickable & Draggable!

Sorting Algorithm — Related pages: