Skip to content
  • About Us
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms and Conditions

Simplified Learning Blog

Learning made easy

  • Java
    • Core Java Tutorial
    • Java 8
    • What is Rest API in java
    • Spring Framework
    • Type Casting in Java | 2 types Implicit and explicit casting
    • Spring Boot Tutorial
      • Spring Boot Rest API Example complete guide
    • Top 50 Java Interview Questions
    • JUnit 5 Tutorial
      • Assertall in JUnit 5
      • Assertions in JUnit 5
    • Java Thread Tutorials
      • How to create thread in Java
      • Multithreading in java
      • Daemon Thread in Java | How to create daemon thread in java
      • Top 40+ Multithreading interview questions
  • AWS
    • What is AWS (Amazon Web Services)
    • AWS IAM (Identity and Access Management)
    • AWS SNS | What is SNS
    • What is SQS | AWS SQS (Simple Queue Service)
    • What is AWS Lambda
    • Top 10 AWS Lambda interview questions
  • Java Codes
  • Software Architecture
    • Software Architecture Performance
    • Performance Principles of Software Architecture
    • System Performance Objective
  • Spring Boot Tutorial
  • Tools
    • JSON Formatter and Validator
  • Tech Blogs
    • Java 21 New Features
    • Is Java Dead? Is java dead, 2023 ?
    • New Features in Java 17
  • Toggle search form

Java 21 New Features

Posted on March 31, 2023April 24, 2023 By Admin No Comments on Java 21 New Features

New Features in java 21

Introduction

Java 21 New Features | Java 21 will be released on September 2023, and it will be a LTS release. LTS is a Long Term Support release by oracle, for which oracle will provide long term support for extended period over the regular one. As of today, what we know so far is that java 21 will add Sequenced Collections – JEP 431.

Table of Contents

Toggle
  • New Features in java 21
  • Introduction
  • Sequenced Collections
    • What is sequenced collections in java 21?
    • The Problem, Why we need Sequenced Collections ?

Sequenced Collections

What is sequenced collections in java 21?

Java 21 introduce sequenced collection, which is a collection whose elements have a defined encounter order (referred to as sequenced – arrange elements in a particular order). A sequenced collection has first and last elements, and the elements between them have successors and predecessors.

Sequenced collection supports processing elements from forward and reverse order.

The Problem, Why we need Sequenced Collections ?

Every collection in java has the order called encounter order, which means that elements in that collection has a well-defined order and iteration will happen on that order, but this is true for sorted collections like sortedSet, all lists as they are sequenced. But what about non-sequential collections without encounter order like a HashSet.

Sequence related operations are inconsistent. e.g. to get first element of list is easy like

List<Employee> employeeList....
employeeList.get(0); // get the first element of the list.

employeeList.get(0); will give you the first element, but getting the last element is a pain as we need to write:

List<Employee> employeeList....
employeeList.get(0); // get the first element of the list.
employeeList.get(employeeList.size()-1); // last element from the list.

Similarly, for LinkedHashSet getting first element from set:

set.iterator().next() 
set.stream().findFirst()

For getting last element from set is not possible without iteration. Not just last to get any element from set we need to stream on it.

Similarly, to reverse the collection, we don’t have any method. The solution is nothing but sequenced collections, as it has these methods:

interface SequencedCollection<E> extends Collection<E> {
    // new method
    SequencedCollection<E> reversed();
    // methods promoted from Deque
    void addFirst(E);
    void addLast(E);
    E getFirst();
    E getLast();
    E removeFirst();
    E removeLast();
}

Methods():

    void addFirst(E)
    void addLast(E)
    E getFirst()
    E getLast()
    E removeFirst()
    E removeLast()
//source openJDK JEP-431

These are the updates on java 21 as of now, will update more as they are released.

See more Java 17 New Features here..

Related

Tech Blogs Tags:Java 21 New Features, New Features in java 21, Sequenced Collections

Post navigation

Previous Post: New Features in Java 17
Next Post: Java util date to String

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • PDF to JSON Convertor
  • System Performance Objective
  • Performance Principles of Software Architecture
  • Calculate date of birth from age in jquery
  • How to convert excel to PDF using java

Recent Comments

No comments to show.

Copyright © 2025 Simplified Learning Blog.

Powered by PressBook WordPress theme