If a program contains only a fixed number of objects whose lifetime is known. Then this is a very simple program.
Typically, a program always creates new objects based on certain conditions that are known to the runtime . Until then, you will not know the number of objects you want, or even the exact type. To solve this pervasive programming problem, you need to create any number of objects at any time and in any location. Therefore, you cannot rely on creating named references to hold each object, because you do not know how many of these references will actually be required.
Most languages offer some way to solve this basic problem. Java has several ways to save objects (which should be referred to as objects ). For example, an array, which is the type supported by the compiler. Arrays are the most efficient way to save a set of objects, which is recommended if you want to save a set of basic types of data. But the array has a fixed size , and in a more general case, you don't know how many objects will be needed when you write your program, or if you need more complex ways to store objects, the limitation of fixed array size is too limited.
The Java Utility Class Library also provides a fairly complete set of container classes to solve this problem, with the basic types of List,Set, Queue , and Map. These object types are also known as collection classes , but since Java's class library uses the term collection to refer to a special subset of the class library, I use the broader term "container" to address them. Containers provide a perfect way to save objects, and you can use these tools to solve a staggering number of problems.
The container also has some other features. For example,Set pairs each value with only one object, andMap is an associative array that allows you to associate certain objects with some other object , and theJava container classes can automatically adjust their size . So, unlike arrays, when you're programming, you can put any number of objects into a container, and you don't have to worry about how big the container should be.
Even if there is no direct keyword support in Java, the gas container class is still a basic tool that can significantly enhance your programming capabilities.
2017-12-31 content from the Java programming idea
Java Container Overview