The first thing to understand is what is called a class set, and what is its role?
The class set is actually a dynamic array of objects, and someone will ask, isn't there an array? What about the class set, actually Ah, the general array has a length limit no, the class set is specifically to solve this limitation, using the class set can easily add any number of data to the array, it is easy to expand and modify.
Let's learn about the schema of the class set, where all class set operations are stored in the Java.util package:
The collection interface is the largest parent interface for storing single-valued collections, but in general development it is not developed directly with collection (the operational meaning is ambiguous), but is developed using its sub-interfaces.
The contents of the list interface allow repetition.
ArrayList is the most commonly used subclass in the list, and is an array-based operation class. You can either increase the data or delete the data. Deletions can be removed in two ways: Depending on the object's content, the corresponding number of the object is deleted.
LinkedList is also a subclass of list, and is a linked list-based operation class.
Vector is also a subclass of list, and it differs from ArrayList in:
Duplicate elements are not allowed in the set interface, and commonly used subclasses have TreeSet (ordered storage), HashSet (hash).
TreeSet can be sorted, so what is the principle of sorting it? To sort an array of objects, it relies on the comparable interface to complete. So for TreeSet, the class where the object resides must also implement the comparable interface and overwrite the CompareTo method.
What is the principle of repeating elements not allowed in the set interface? By covering the hashcode () and Equals () two methods in the object class, it is possible to make a repetition of the objects ' elements. Not to be continued ...
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The class set in Java