Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Overview

This document will outline when to use Guava's ImmutableMap/ImmutableSet and Java's Map.of and Set.of.

...

Code Block
languagejava
themeConfluence
titleJava UnmodifiableMap Example
collapsetrue
Map<String, String> mutableMap = new HashMap<>();

Map<String, String> unmodifiableMap = Collections.unmodifiableMap(mutableMap);

...

Code Block
languagejava
themeConfluence
titleGuava ImmutableMap Examplecollapsetrue
ImmutableMap<String, String> immutableMap = ImmutableMap.copyOf(mutableMap);

...

Code Block
languagejava
themeConfluence
titleJava Map.of Examplecollapsetrue
Map<String, String> immutableMap = Map.of("A", "Apple", "B", "Ball", "C", "Car")

...