Class SequencedCollectionsExamples

java.lang.Object
net.jrodolfo.java_evolution.java21.SequencedCollectionsExamples

public class SequencedCollectionsExamples extends Object
Demonstrates sequenced collections, introduced in Java 21.

Java had many ordered collections before Java 21, but there was no shared API for first element, last element, or reversed views. Generic code had to know whether it was dealing with a List, deque, ordered set, or ordered map.

Sequenced collection interfaces give encounter-ordered data structures a common vocabulary. The reversed() operation returns a reversed view rather than requiring callers to make a defensive copy just to look at the same data from the other direction.

  • Constructor Details

    • SequencedCollectionsExamples

      public SequencedCollectionsExamples()
  • Method Details

    • summarizeSequence

      public String summarizeSequence(List<String> values)
      Uses first, last, and reversed operations from SequencedCollection.
      Parameters:
      values - ordered values
      Returns:
      a summary of sequence operations
    • summarizeMapOrder

      public String summarizeMapOrder()
      Uses first and last entry operations from SequencedMap.
      Returns:
      a summary of map encounter order