15th days: Set, Set
1. Set: Collection
Some methods (for more methods, refer to the help documentation): add (Object obj), delete remove ()/removeAll ()/clear (), change set (index, Object) query get (index), iterate iterator ()-> traverse
1: List Interface
Features: ordered and repeatable operations can be performed with subscripts.
Common classes;
1.1 ArrayList: The underlying layer stores data in arrays, which results in high search efficiency and low addition, deletion, and modification.
1.2 shortlist: The underlying layer stores data in the form of a linked list, with low search efficiency and high addition, deletion, and modification.
2: Set Interface
Feature: unordered: the order in which the data is put is different from the order obtained. It cannot be repeated.
The method is the same as the Collection method.
2.1: HashSet: Use a hash table to remove duplicate elements and determine whether a piece of data is duplicated. First, determine whether the hash value of the modified data is the same as the value in the created hash table, if they are the same, they are repeated. If the equals method is called differently to compare whether they are the same, if true is returned, the same data is not added; otherwise, the data is added.
2.2: TreeSet: uses a red-black tree (balanced binary tree) structure to store data. Deduplication and sorting are removed based on the return values of the compareTo method. The compareTo method is in the Comparable interface. You can rewrite this method to customize the sorting rules when implementing the interface.
3: Generic programming, Representation <>, <> multiple letters can be placed in angle brackets, separated by "," <T, E>
When using the set, advance the running errors to the compilation period. When creating a set, define the type of the Set element.
3.1: generics are defined on methods. Generic method. The return value type can also be expressed as a generic method.
Public <T> return value type method name (T t ){
Method body.
}
Public <T> T method name (T t ){
Method body.
Return t;
}
T; indicates any type of referenced data. The type name can be expressed by any letter or word, which is generally expressed by an uppercase letter.
? : Indicates any reference type. There may be multiple Reference Data Types
? Extends T: represents any T or T subclass.
? Super T: indicates the parent class of any T or T.
3.2: Generic Type
Class Name <T> {
}
3.3: generic interface
Interface Class Name <T> {
}