Lesson 21Understanding Collections

This lesson is a look at the Java Collections Framework. Collections are data structures that allow you to store multiple values in a more flexible manner than simple arrays. We'll look at common Collections Framework classes and the relationship between interfaces and implementations in this context.

COLLECTIONS IN JAVA

In the broadest sense, a collection is simply a data structure that groups multiple elements together into a single unit. Collections usually represent a group of related data such as a class of students, a group of addresses, or a list of classes in a school schedule. We make extensive use of collections in programming to manipulate groups of related data.

The Java Collections Framework is a library of code that allows programmers to manipulate groups of related objects. Because the Collections Framework is available to all Java programmers, we gain the benefit of not having to “reinvent the wheel” for collections manipulation. Because this framework is widely used, the implementation of these algorithms has been honed over time to be fast, efficient, and bug-free.

Another benefit of the framework is that there is one application programming interface ...

Get Job Ready Java 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.