To summarize what youve seen so far, your first and most efficient choice to hold a group of objects should be an array, and youre forced into this choice if you want to hold a group of primitives. In the remainder of this chapter well look at the more general case, when you dont know at the time youre writing the program how many objects youre going to need, or if you need a more sophisticated way to store your objects. Java provides a library of container classes to solve this problem, the basic types of which are List, Set, and Map. You can solve a surprising number of problems by using these tools.
Among their other characteristicsSet, for example, holds only one object of each value, and Map is an associative array that lets you associate any object with any other objectthe Java container classes will automatically resize themselves. So, unlike arrays, you can put in any number of objects and you dont need to worry about how big to make the container while youre writing the program.