The origin of the collection:
Storing multiple objects requires container-type variables to be stored, arrays and StringBuffer are container types, but StringBuffer can only store strings, not meet demand, and the length of the array is fixed and cannot adapt to changing needs, in order to accommodate this need, Java provides a collection class for us.
The difference between a collection and an array:
1. Length difference:
Arrays are fixed-length
Sets are variable-length
2, the content difference:
Arrays are stored in the same data type
The collection stores the objects, which can be different types of objects
3. The data type problem of the element:
Arrays can store both the base data type and the reference type
Collection can only store reference types
Inheritance architecture for Collections:
A collection is used to store multiple elements, but there are different requirements for storing multiple elements, such as requiring that elements not be duplicated, such as ordering. Java provides different sets of classes for different requirements. The data structure of these multiple collection classes is different, the structure is not important, it is important to be able to store things, and also can use these things, such as adding and deleting changes and so on. In this case, the collection classes are made up of generality, and we extract these commonalities upward and eventually we can form a set of inheritance architectures, such as:
In the above class diagram, the real line border is the implementation class , such as Arraylist,linkedlist,hashmap, and so on, the polyline border is an abstract class , such as Abstractcollection,abstractlist,abstractmap, and the point line border is the interface , such as Collection,iterator,list.
Java collection classes