In Java programming, it is common to use vector, enumeration, ArrayList, Collection, Iterator, set, List and other collection class interfaces.
1. Vector class and enumeration interface
The vector class is an advanced data structure provided by the Java language that can be used to hold a series of objects, Java does not support arrays, and the vector class provides a function similar to "dynamic arrays". The vector class is a good choice if we cannot predetermine the number of objects to be saved, or if we need to make it easy to get the location of an object.
2.Collection interface and Iterator interface
The collection interface is used like a vector class, except that the name of the method differs. We want to take out all the objects that are stored in the implementation of the collection interface object, and we must also return a iterator interface object through the Collection.iterator method, which is very similar to the function of the enumeration interface with the iterator interface. The JAVA2 platform's data structure Class designer could have expanded the enumeration interface without creating a new interface for iterator. But they do not like the lengthy name of the enumeration interface method, thus creating a new interface for iterator and shortening the length of the method name.
According to the Java syntax, the object cannot be created directly with the collection interface class, and the object must be created with a class that implements the collection interface, and the ArrayList class is a class that implements the collection interface. Instead of using the vectors and enumeration examples above, we will write them in ArrayList and Iteartor to understand the relationship and usage of these classes.
All methods in the ArrayList class are asynchronous, so in the absence of multi-threading security problems, it is better to use ArrayList and the program will be more efficient. In the thread security issue, and our program does not deal with itself (processing refers to the call ArrayList code or method plus synchronous processing), only with the vector.
2. Comparison of collection class interfaces
There are also several collection class interfaces set, List, below which are the collection and their comparisons.
Collection----objects do not have a specified order, allowing repeating elements.
Set----objects do not have a specified order, and duplicate elements are not allowed.
Lists----objects in a specified order, allowing repeating elements.
Vector, enumeration, ArrayList, Collection, Iterator, set, List and other collection class interfaces