Remember the first time you heard the container in Java was a brother Siang, and it was very mysterious. Then let's uncover the veil of mystery today.
first, what is a container?
When writing a program, we often need to manage a large number of object references. To achieve effective collation management, we often place similar references in the same data container. Because the data container holds the object reference which we may need to use at any time, the general data container should be able to provide convenient query, traverse, modify and other basic interface functions.
The early OOP language implements the centralized management and maintenance of the reference set by means of arrays.
But arrays, where the size of the array needs to be determined in advance, does not allow the size to be modified, causing its ability to function as a flexible data container greatly reduced.
In order to conveniently use the data container for reference management, Java provides a wealth of data containers to meet the diverse needs of programmers.
containers in Java:
6 interfaces:
The collection interface defines a method for accessing a set of objects, and the sub-interface set and list define the storage methods separately. The data objects in set cannot be duplicated in order, and the list is the opposite.
The implementation class definition of the map interface stores Key-value pairs, because key-value pairs are identified by keys, so the key values cannot be duplicated.
Iterator interface: Mainly used when it comes to traversal. All container classes that implement the collection interface have a iterator method to return an object that implements the iterator interface.
Comparable interface: When two objects involve comparisons, use one of its only compareto methods.
What is the difference between the collection interface and the collections class?
Java.util.Collection is a collection interface. It provides a common interface method for basic manipulation of collection objects.
Java.util.Collections is a wrapper class. It contains a variety of static polymorphic methods related to set operations. This class cannot be instantiated, just like a tool class that serves the Java collection framework.
Summary: Each interface in the container in addition to the comparable interface only one method, the other has a lot of methods, the type of specific methods and usage of consulting API is particularly important, the ability to check the API document in this embodiment of the incisively and vividly. Although the veil has been uncovered, it is a preliminary understanding that needs to be understood and used slowly.
First knowledge of containers in Java