I. Introduction to several important interfaces and classes
1. List (ordered, repeatable)
List of objects are ordered, but also can be repeated, list is concerned about the index, has a series of index-related methods, query fast. Since inserting or deleting data into the list collection is accompanied by the movement of the subsequent data, all insertions are slow to delete data.
2. Set (unordered, cannot repeat)
The objects stored in the set are unordered and cannot be duplicated, and the objects in the collection are not sorted in a particular way, simply by adding the object to the collection.
3. MAP (key value pair, key unique, value not unique)
The Map collection stores key-value pairs, keys cannot be duplicated, and values can be duplicated. According to the key to get the value, the map set to traverse the first get the set set of keys, the set set to traverse, to get the corresponding value.
Second, traverse
The following four common output methods are available in the class set:
1) Iterator: Iterative output, is the most used output mode.
2) Listiterator: is the sub-interface of the iterator, specifically used to output the contents of the list.
3) foreach output: A new feature provided after JDK1.5 that allows you to output an array or a collection.
4) for Loop
The code examples are as follows:
For the form: for (int i=0;i<arr.size (); i++) {...}
foreach form: for (int i:arr) {...}
form of Iterator: Iterator it = Arr.iterator ();
while (It.hasnext ()) {object o =it.next (); ...}
Iii. ArrayList and LinkedList
There is no difference in usage between ArrayList and LinkedList, but there are differences in function. LinkedList often used in the case of more additions and deletions and very few query operations, ArrayList is the opposite.
Iv. Collection of Maps
Implementation classes: HashMap, Hashtable, Linkedhashmap, and TreeMap
Java Collection Class Rollup