The last couple of years was the year of releases for Java developers. With versions of JDK 9 to JDK 15, Spring 5, Spring Boot 2.0, and Spring Security 5.0, there was so much to learn for Java developers and all at once, but like many others, I didn't make a good process, and I am looking to turn it around this year. One of my top priority goals for this year is to learn new Java features as quickly as possible to write more about them. It's also essential for you to learn modern Java features to write better code and improve your day-to-day productivity with Java. The Java 9 release intends to change the way Java developers used to write code. It introduces a modular JDK so that developers can only include the modules that they need.
Friday, April 25, 2025
Wednesday, April 19, 2023
How to create Immutable List, Set, and Map in Java? List.of(), Set.of() and Map.of() Examples
Hello guys, this is my first article in Java 9 features on this blog, and today you'll learn about my favorite feature "factory methods for collection", which is introduced as part of JEP 269. The JEP stands for the JDK enhancement proposal. If you have worked in Groovy or Kotlin then you know that how easy is to create the list with elements using collection literals e.g. to create a list of 1, 2, 3 you can simply write val items = listOf(1, 2, 3). Unfortunately, Java doesn't support that yet but things have been improved with the factory methods for collection in JDK 9 and it's almost like that. JDK has added static factory methods like of() on to basic Collection interfaces which you can use to create a list of items.
Labels:
core java
,
java 9
,
java collection tutorial
Subscribe to:
Posts
(
Atom
)