Java Tutorials for Beginners and Professionals

Java 9 Immutable Set Example

This example demonstrates how to create immutable Set 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) Set.

Java 9 immutable Set example

Prior to Java 9, the creation of immutable Set was some kind of verbose task. For Example, to create an empty immutable Set 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.