The Artima Developer Community
Sponsored Link

Java Buzz Forum
Immutable empty collections and iterators

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
News Manager

Posts: 47623
Nickname: newsman
Registered: Apr, 2003

News Manager is the force behind the news at Artima.com.
Immutable empty collections and iterators Posted: Aug 2, 2016 1:05 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by News Manager.
Original Post: Immutable empty collections and iterators
Feed Title: JavaWorld
Feed URL: http://www.javaworld.com/index.rss
Feed Description: JavaWorld.com: Fueling Innovation
Latest Java Buzz Posts
Latest Java Buzz Posts by News Manager
Latest Posts From JavaWorld

Advertisement

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.

To read this article in full or to leave a comment, please click here

Read: Immutable empty collections and iterators

Topic: Java Productivity Tips: Top Picks from the Community Previous Topic   Next Topic Topic: 38% off Philips Automatic Pasta Maker - Deal Alert

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use