Lesson 11Introduction to Collections
So far you’ve been introduced to only one way of storing a collection of objects—with Java arrays, which are good for storage but fall short when you need to dynamically add, remove, or traverse the data. There are a number of classes and interfaces in the package java.util
that are quite handy when multiple instances of some objects (collections) have to be co-located in memory. This lesson introduces you to several of them.
You can find more collections in the java.util.concurrent
package, but you review those in digging_deeper_into_concurrent_execution after you become familiar with the concept of multithreading. Together, the collection classes and interfaces located in java.util
and java.util.concurrent
are often called Java Collection Framework.
Collection classes implement different interfaces, and several are covered in this lesson. The image in Figure 11-1 is taken from Oracle Java documentation. It depicts the top-level core collection interfaces.
Java 8 introduced substantial improvements in collection data manipulation, and I highlight these changes in this lesson as well as in Lesson 20.
Arrays Revisited
Java collection classes enable the storing of primitives or object references in one place in memory. You were introduced to arrays in Chapter 5: Arrays let you store ...
Get Java Programming 24-Hour Trainer, 2nd Edition 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.