Immutable Data Structures in Java

As part of some of the coding interviews I’ve been conducting recently, the topic of immutability sometimes comes up. I’m not overly dogmatic in it myself, but whenever there’s no need for mutable state, I try to get rid of code which makes code mutable, which is often most visible in data structures. However, there seems to be a bit of a misunderstanding on the concept of immutability, where developers often believe that having a final reference, or val in Kotlin or Scala, is enough to make an object immutable. This blogpost dives a bit deeper in immutable references and immutable data structures.

Benefits of Immutable Data Structures

Immutable data structures have significant benefits, such as:

Access and Non-Access Modifiers in Java

In Java, a modifier has a reserved keyword that is included in the definition of class, method, and variables. A modifier adds some meanings to these definitions. Modifiers are also called specifiers.

These modifiers are classified into two categories. Some of the modifiers are called access modifiers and some are called non-access modifiers.