Have you ever wondered why the java.util.Collections class includes various "empty" class methods, which return immutable empty collections and immutable empty iterators? This post answers this question.
Why are the returned empty collections and iterators immutable?
The returned empty collections and empty iterators are immutable (unchangeable) so that they can be safely used in multithreaded contexts.
An immutable empty list of flowers
The Collections class's various "empty" class methods offer a useful alternative to returning null (and avoiding potential java.lang.NullPointerExceptions from being thrown) in certain contexts. Listing 1 presents the source code to an application that demonstrates the benefit of an immutable empty list.