Chapter 14

The Collections Framework

WHAT YOU WILL LEARN IN THIS CHAPTER

  • What sets, sequences, and maps are, and how they work
  • The capabilities of the EnumSet<E> collection class
  • What a Vector<T> collection object is and how to use Vector<T> objects in your programs
  • How to manage Vector<T> objects so that storing and retrieving elements is typesafe
  • What a Stack<T> collection is and how you use it
  • How you use the LinkedList<T> collections
  • How you store and retrieve objects in a hash table represented by a HashMap<K,V> object
  • How you can generate hashcodes for your own class objects

In this chapter you look at the Java collections framework, which consists of generic types that represent sets of collection classes. These types are defined in the java.util package, and they provide you with a variety of ways for structuring and managing collections of objects in your programs. In particular, the collection types enable you to deal with situations where you don’t know in advance how many objects you need to store, or where you need a bit more flexibility in the way in which you access an object other than by the indexing mechanism provided by an array.

UNDERSTANDING THE COLLECTIONS FRAMEWORK

The Java collections framework is a set of generic types that you use to create collection classes that support various ways for you to store and manage objects of any kind in memory. Recall from Chapter 13 that a collection class is simply a class that organizes a set of objects of a given ...

Get Ivor Horton's Beginning Java®, Java 7 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.