Java Tutorials for Beginners and Professionals

Java 9 Immutable List Example

This example demonstrates how to create immutable lists with the new Java 9 Collections factory methods

With Java 9 release, Oracle is going one step foreword in acquiring working practices form other popular JVM languages like Kotlin, Guava, Scala, etc. This is done with proper respect to backwards compatibility and consistency of syntax across the JDK. One of those new Java 9 features is the creation of immutable (unmodifiable) Lists.

Java 9 immutable list example

Prior to Java 9, the creation of immutable List was some kind of verbose task. For Example, to create an empty immutable list with pre Java 9 versions we used following code:

Many of the tutorials you will find here are based on the book Mastering Java 9 written by Dr. Edward Lavieri and Peter Verhas. This book will provide you with complete and deep understanding of the new Java 9 concepts and tools.