8 Collections and maps

This chapter covers

  • Common mistakes when adding or looking for an element of unrelated type in a collection
  • Handling nulls in collections and maps
  • Modifiable and unmodifiable collections
  • Concurrent modification of collections
  • Problems using the List.remove() method
  • How to implement iterators properly

The Java Collection API appeared long ago in Java 1.2. The world was quite different then: Java had no parameterized types (generics), mutable objects were in favor, and nulls were generally accepted values. Over time, the language and the way people write programs has changed significantly. Yet with all that change, the old collection API remains ubiquitous in modern programs. Some outdated design decisions negatively ...

Get 100 Java Mistakes and How to Avoid Them now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.