Class SortingExamples

java.lang.Object
net.jrodolfo.java_evolution.java02.SortingExamples

public class SortingExamples extends Object
Demonstrates Java 2 collection sorting with Comparable and Comparator.
  • Constructor Details

    • SortingExamples

      public SortingExamples()
  • Method Details

    • sortNaturally

      public List sortNaturally(List numbers)
      Sorts values by their natural ordering.
      Parameters:
      numbers - numbers to sort
      Returns:
      sorted numbers
    • sortByLength

      public List sortByLength(List names)
      Sorts names by length using a comparator object.
      Parameters:
      names - names to sort
      Returns:
      names from shortest to longest