Introduction to JEP 431
- Variability in ordered elements support.
- Lack of consistency in supertype.
- Absence of standardized methods.
- Complexity in Reverse Iteration.
The JEP 431 is known as Sequenced Collections, It introduces some new interfaces and methods to represent collections in Java that maintain a specific order for their elements. This JEP addresses the lack of a standardized way to work with ordered collections in Java's existing collections framework, which has led to inconsistencies and limitations in working with such collections.
The main motivations are to resolve the below questions related to ordered collections in Java,
What's are Sequenced Collections
These are three new interfaces that are added to the Java Collections framework SequencedCollection, SequencedSet and SequencedMap.

As you may see prior to Java JDK 21, we can fetch the first and the last element of an ArrayList as follows,
List<String> unorderedCollection = new ArrayList<>();
unorderedCollection.add("Sam");
unorderedCollection.add("Alex");
unorderedCollection.add("Jim");
String listFirstElement = unorderedCollection.iterator().next();
String listLastElement = unorderedCollection.get(unorderedCollection.size() - 1);
Now with the new SequencedCollection interface getFirst() and getLast() methods, this looks much simpler and easier to read.
String listFirstItem = unorderedCollection.getFirst();
String listLastItem = unorderedCollection.getLast();
Similarly lets take a look at SequencedSet. The Sequenced Set is a Set that is also a Sequenced Collection with no duplicate elements, It inherits the methods from the Sequenced Collection and includes specialized methods for adding elements while maintaining order.
Example:
public static void main(String... args) {
LinkedHashSet<String> linkedHashSet = new LinkedHashSet();
linkedHashSet.add("Sam");
linkedHashSet.add("Alex");
linkedHashSet.add("Mike");
linkedHashSet.addFirst("Firsty");
linkedHashSet.addLast("Lasty");
System.out.println(linkedHashSet.reversed());
}
Output:
[Lasty, Mike, Alex, Sam, Firsty]
Finally, let's take a look at SequencedMap.
public static void main(String... args) {
LinkedHashMap<String, String> countryMap = new LinkedHashMap<>();
countryMap.put("USA", "Chicago");
countryMap.put("India", "New Delhi");
countryMap.put("Japan", "Tokyo");
countryMap.putFirst("France", "Paris");
countryMap.putLast("UK", "London");
System.out.println(countryMap.firstEntry());
System.out.println(countryMap.lastEntry());
System.out.println(countryMap.pollFirstEntry());
System.out.println(countryMap.pollLastEntry());
System.out.println(countryMap.reversed());
}
Conclusion
tl;dr - Sequenced Collections
Facing issues? Have Questions? Post them here! I am happy to answer!
- Steps to Install Java 21 (LTS JDK) on Windows 11
- Setting Up VS Code with Java JDK 21
- [JEP 430] Java JDK 21 New Feature - String Templates (Preview)
- Java JDK 21: JEP 439 - An Improved Generational Z Garbage Collector (ZGC)
- Java JDK 21 LTS Version Release Date (General Availability)
- Installing Java JDK 21 Final Release Candidate
- Fix - Unsupported major.minor version 65.0 (Java JDK 21)
- How to use Java JDK 21 with IntelliJ
- How to Enable Java JDK 21 Preview Features on IntelliJ
- Java JDK 21 - The Latest LTS Version
- How to install and Use Java JDK 21 Initial Release Candidate
- [JEP 431] Java JDK 21 New Feature - Sequenced Collections
- 21 Essential Mac Terminal Shortcuts for Devs and DevOps to Boost Productivity - MacOS
- error CAML Query containing special characters - SharePoint
- Jupyter Notebook Markup Cell Table Example - Python
- How to Force Quit Microsoft Excel Application on Mac - Microsoft
- How to install Microsoft OneDrive on Mac Sonoma 14 - MacOS
- How to close all tabs of Notepad++? - NotepadPlusPlus
- Word wrap text in Notepad++ - NotepadPlusPlus
- Reading JSON file in Python with Examples - Python