Class StreamAdvancedSortingExample

java.lang.Object
modernfeatures.streams.StreamAdvancedSortingExample

public class StreamAdvancedSortingExample extends Object
Demonstrates advanced sorting techniques with Java Streams and Comparators.

Includes examples of:

  • Sorting by string length (ascending and descending)
  • Sorting by the last character of each name
  • Sorting in reverse (alphabetical) order
Edge cases are handled: the list is checked for null and emptiness before processing.
  • Constructor Details

    • StreamAdvancedSortingExample

      public StreamAdvancedSortingExample()
  • Method Details

    • main

      public static void main(String[] args)
      Runs advanced sorting examples on a sample list of names.
      1. Checks for null and empty lists to prevent runtime errors.
      2. Sorts names by length (shortest to longest).
      3. Sorts names by length (longest to shortest).
      4. Sorts names by the last letter (assumes non-empty strings).
      5. Sorts names in reverse (alphabetical) order.
      Parameters:
      args - Command-line arguments (not used).