Class SequencedCollectionsExamples
java.lang.Object
net.jrodolfo.java_evolution.java21.SequencedCollectionsExamples
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionUses first and last entry operations fromSequencedMap.summarizeSequence(List<String> values) Uses first, last, and reversed operations fromSequencedCollection.
-
Constructor Details
-
SequencedCollectionsExamples
public SequencedCollectionsExamples()
-
-
Method Details
-
summarizeSequence
Uses first, last, and reversed operations fromSequencedCollection.- Parameters:
values- ordered values- Returns:
- a summary of sequence operations
-
summarizeMapOrder
Uses first and last entry operations fromSequencedMap.- Returns:
- a summary of map encounter order
-