1. Introduce the collection Framework Structure
Note: List, set inherits from collection, and map does not inherit collection.
Ii. Differences between collection and collections
1. java. util. Collection interface: it is the upper-level interface of the Collection class. Its inherited interfaces mainly include set and list.
2. java. util. Collections class: it is a helper class for collection classes. It provides a series of static methods for searching, sorting, thread security, and other operations on various sets.
Iii. interfaces to be implemented by the collection framework
Both comparable and comparator are used to compare and sort elements in a set. Comparable only sorts the methods defined inside the set, while comparator sorts the methods outside the set. Therefore, to achieve sorting, You need to define the comparator interface method outside the set or implement the comparable interface method in the set.
1. Implement the java. Lang. Comparable interface (set itself implements this interface)
Override the unique method int compareto (t o) of this interface.
Public class user implements comparable {} // The user class inherits this interface
Arrays. Sort (users );
2. Implement the java. util. comparator interface (define a class outside the set to implement this interface)
Two methods to override this interface: int compare (T O1, t O2) and Boolean equals (Object OBJ ).
Public class samplecomparator implements comparator {}// this interface is not inherited by the user class
Arrays. Sort (array, new samplecomparator () during use; // you need to input the instantiated object of this interface.
Iv. differences among various containers 1. Differences between arraylist and vector
Similarities: both inherit from the list interface, which is an ordered set that allows repeated elements. You can retrieve elements by index number. (Hashset and other sets cannot be repeated. elements cannot be retrieved by index number)
Differences:
(1) vector is thread-safe (that is, thread synchronization between its methods) and is suitable for multithreading. arraylist threads are not secure and efficient.
Note: vector and hashtable are old and thread-safe. arraylist and hashmap are provided by Java2, and threads are not secure.
(2) Both have an initial capacity (you can set it yourself). When the storage element exceeds the capacity, the default growth of vector is doubled (you can set it yourself ); arraylist increased by 1.5 times (not set by yourself ).
2. Differences between hashmap and hashtable 3. Differences between list and MAP 4. Interfaces of list, set, and map 5. Features of access elements 5. arraylist, vector, memory list storage performance and features 5. Remove repeated elements from the vector set 6. The elements in the set cannot be repeated. How can we distinguish whether to be repeated? = or equals ()? What are their differences? 7. What are the main methods of the collection classes you know? 8. The two objects have the same value (X. Equals (y) = true), but different hashcodes exist. Is this sentence true? 9. Put objects in the treeset. If both the parent class and the subclass object are put, will the parent class or the compareto () of the subclass be used for comparison, or will an exception be thrown? 10. Name five common classes, packages, and interfaces
57-71 container test site