The Java Collection class is located under the Java.util package, and as its package name implies, the Java Collection class is a set of tools. It is like a Craftsman's toolbox, which provides convenience and efficiency to the people who use it. The Java Collection framework is not an advanced technology or a bitter knowledge, it simply sets the common data structures and algorithms together so that we can process the data more easily and efficiently without having to reinvent the wheel. The Java collection classes fall into two main categories: collection and map. Look at collection first. Collection translation to Chinese is the meaning of "set". Learning mathematics knows that a set is a group of elements that each unit element is a single individual. We can think of collection as a lattice box with a ball in it, where each lattice in the box can only have one ball: Map. Map has the meaning of "mapping". We know that mappings occur in pairs, so the unit elements of the mappings are a pair of associated individuals. We can also think of map as a box with a ball in it, the difference is that each box in each lattice is two related balls: The following figure, the white is the interface, the red is the middle of the class: Why do we separate the interface and the class? Because we are in the actual operation, the class is generally used to instantiate, the interface is generally used for upward transformation. You can't have a new interface, can you? And we're mainly learning about specific classes, not interfaces.
This diagram is great for us to learn about Java collections. I summed up a few points:
- The hierarchical relationships in the reference graph are learned from top to bottom, so that we can learn the common approach together and only learn its unique methods when learning specific classes.
- When using ArrayList, we know that he belongs to collection, and the common method for adding elements to collection is Add. When we use HashMap, we know that it belongs to map, and the common way that map adds elements is put. So we don't confuse the way they add elements.
- Select data structure is, we can first analyze whether it is collection or map appropriate. Then recall from the top down which classes are available.
- Allows us to better understand the collection class. As far as I am concerned, when using ArrayList, it is not clear that his hierarchy tree always feels "not at ease". This class is like appearing out of nowhere, not knowing where it comes from and where it can go. If there is a hierarchy chart there is a feeling that "all the obstacles are gone" and there is a sense of global pleasure.
Java collection classes