There was a note before, about collections and generics, these days looking at the documentation of several interfaces in the Java collection, the mind is very confusing, until you see the Oracle "the Collections Framwork" page, the organization is clear, now to organize.
Why do I need a collection?
It is often necessary to create a lot of objects in the application to do some work, so we need to organize these a certain number of objects for unified management.
An array of objects satisfies us that if the number of objects is clearly limited and the life cycle is known, it is very simple and intuitive to use an object array for management.
Once an array is created, its capacity is fixed and can no longer be changed in its life cycle. However, the program always creates new objects at run time based on certain conditions, before which we cannot predict the number of objects we need or even know the exact type. So how do you manage any number of objects at any time? The collection was born for this.
PS: The two ways of organizing and managing objects are "array-based", "collection-based", in the set interface mentioned below, there is a method called "ToArray ()", known as the bridge between the two ways.
Second, the collections Framwork
What does the Java collection framework contain, and summarizes it according to its API specifications?
1, Collection interfaces, that is, the collection interface.
Implementing these interfaces is the primary way we use collections. It has two root interfaces, collection and maps.
As for the hierarchy of interfaces, here is no longer a repeat
2, implementations, that is, the interface implementation class
is a variety of implementations of the collection interface.
You can see that there are many types of implementation classes listed in the API specification, the most fundamental and most important of which is the general-purpose implementations, the generic implementation class, which contains some of the data structures we use most often. The following table is a common interface and their common implementation class:
As for the other implementations, when it is necessary to look again, know the implementation of a variety of classes on the line.
3, Algorithms, algorithm
Provides a number of basic algorithm implementations.
The static methods of these algorithms are in a class called "Collections" (java.util.Collections).
4. Infrastructure, basic facilities
This is not mentioned in the book I read, and the type of it is very clear about its role. There are 4 types of "infrastructure" in it:
- Iterators:iterator, Listiterator
- Ordering:comparable, Comparator
- Runtime Exceptions: (two classes) unsupportedoperationexception, concurrentmodificationexception
- Performance:randomaccess
5. Array Utilities
It contains the Arrays class (Java.util.Arrays) because there are many static methods that need to be used!
Attached to a book "Panorama of the Set frame": ·
Elements in the Java collection framework