1) hierarchical structure of the Java Collection framework
2) use the common methods defined by the collection interface to operate on the set and linear table.
3) use the iterator interface to traverse the set
4) use the enhanced for loop of JDK to replace iteration iterator for set Traversal
5) be familiar with the set interface and know when and how to use hashset, javashashset, or treehashset to store elements.
6) use the comparator interface to compare elements
7) be familiar with the list interface and know when and how to use arraylist or sorted list to store elements.
8) differentiate vector and arraylist, and learn how to use vector and stack.
9) use the general type of jdk1.5 to simplify Program Design
10) understand the differences between collection and map, and know when and how to use hashmap, linkedhashmap, and treehashmap for storage.
11) use the static method in the collections class
12) use static methods in the arrays class
The above is the content of the Java Collection framework. If you are not familiar with any of them, please take a good look.
Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------
Java Collection architecture supports three types of collections: Set, list, and map, which are defined in set, list, and map respectively. The Set instance stores a group of distinct elements (sets), the list instance stores a group of ordered elements (tables), and the map stores a group of objects-key value ing.
The overall architecture is as follows. It is very important to include inheritance relationships and implement classification at a Glance:
Collection interface:
Set interface:
Hashset class
Linkedhashset specific class
Treeset class
List interface:
Arraylist
Categorlist specific classes
Vector class specific Vector class
Stack classes
Map interface:
Hashmap class
Linkedhashmap class
Treemap class
Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------
1) First, the collection interface is the Root Interface for processing object sets. It provides some common methods, such as size, iterator, add, and remove.
2) the set and list interfaces are all extended from collection. Set is the set mentioned in high school mathematics. It cannot be duplicated or unordered. A list is like a table, which can be repeated. elements are placed sequentially in the table.
3) Then let's talk about three implementations of the Set interface:
Hashset objects must implement the hashcode method. Most classes of Java API implement the hashcode method.
Linkedhashset extends the hashset and supports sorting of elements in the rule set. The elements in the hashset are unordered. In linkedhashset, the elements can be extracted in the order of element insertion sets.
Treeset ensures that the elements in the set are ordered. There are two ways to achieve comparison between objects: 1. The objects added to the treeset implement the comparable interface; 2, specify a comparator for the element of the rule set)
TIPS:
If you want to extract elements in the order of element insertion sets, use javashashset to store the elements in the order they are added.
Without the above requirements, hashset should be used, which is more efficient than javashashset.
The sequence hashset is stored in sequence according to the order of addition. To add ordered attributes to the set elements, you need to use treeset (the Set elements have a sorting relationship ).
4) several implementations of list
The most important of course is the arraylist (not synchronized) and the sort list, a list of dynamically scalable capacity implemented by arrays, and a list implemented by chain.
There is also the vector (synchronization) class, which contains the synchronization method for accessing and modifying vectors, just like arraylist.
The Stack class inherits from the Vector class, but is generally used only as the stack function. Do not use the functions in the vector.
5) Map
Map is a ing, which is essentially different from set and list.
Hashmap, chained hashmap, and treehashmap are three ing implementations. In terms of name, the analysis of the three implementations of the above set is similar.
Hashmap: High Efficiency
Likedhashmap: stores data in the order of addition, which can be retrieved in the order of addition.
Treehashmap: Sorting
Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------
Collections class and arrays class:
Collections class (note not collection): provides a number of static methods to manage collections and linear tables (most of which are used to operate linear tables, such as copying and sorting linear tables, refer to the API)
Arrays class: provides various static methods for sorting, searching, comparing, and filling elements in arrays.
Certificate ----------------------------------------------------------------------------------------------------------------------------------------------------
General Usage:
It refers to the use of generics in the Java set to specify the type of elements to be added:
Hashmap <K, V> map = new hashmap <K, V> () where K and V are two class types, indicating that only objects of the K and V types can be filled in.
In addition, only objects can be added to the collection. For the basic data type, it is automatically converted to the corresponding packaging class.
Certificate --------------------------------------------------------------------------------------------------------------------------------------------------