(i). Java Collection Framework outlines (pictures from the network): The following two graphs can say the entire set of frame hierarchy and Structure!
(PS) Here is a lot of summary is I put a training organization video all read, found that the teacher summed up very well put it here, right when you write code when you do not remember to give yourself a reminder role.
(b). Collection Collection Summary
Collection
|--list Orderly, repeatable
|--arraylist
The underlying data structure is an array, query fast, and delete slowly.
Thread insecure, high efficiency
|--vector
The underlying data structure is an array, query fast, and delete slowly.
Thread-safe, low-efficiency
|--linkedlist
The underlying data structure is linked list, query slow, delete quickly.
Thread insecure, high efficiency
|--set disorder, the only
|--hashset
The underlying data structure is a hash table.
How to guarantee the uniqueness of the element? Relies on two methods: Hashcode () and Equals (), which can be generated automatically in development
|--linkedhashset
The underlying data structures are linked lists and hash tables
The chain list ensures that the elements are orderly
Guaranteed element unique by hash table
|--treeset
The underlying data structure is a red-black tree.
How do you ensure that elements are sorted? (1). Natural sort (2). Comparator sort
How to guarantee the uniqueness of the element? Depends on whether the return value of the comparison is
(iii). Set Set:
(1) Features of Set set
Unordered, unique
(2) HashSet Collection
A: The underlying data structure is a hash table (is an array of elements as linked lists)
B: Hash table bottom-dependent two methods: Hashcode () and Equals ()
Execution order:
First, compare whether the hash value is the same
Same: Continue to execute equals () method
Returns true: The element is duplicated, not added
return false: Add elements directly to the collection
Different: Add elements directly to the collection
C: How to guarantee the uniqueness of the element?
Guaranteed by Hashcode () and Equals ()
D: When developing, the code is very simple and can be generated automatically.
E:hashset Store strings and traverse
F:hashset Store a custom object and traverse it (the same element is the same as the object's member variable value)
(3) TreeSet Collection
A: The underlying data structure is a red-black tree (a self-balancing two-fork tree)
B: Guaranteed Ordering of elements
A: Natural sorting (elements are comparative)
Implementing the comparable interface for the class to which the element belongs
B: Comparator sorting (collection with comparison)
Let the collection construct method receive comparator implementation class object
(iv). Map (Master)
(1) An object that maps the key to a value. A map cannot contain duplicate keys, and each key can be mapped to at most one value.
(2) What is the difference between map and collection?
A:map stores elements that are key-value pairs, unique keys, and values that can be duplicated. Couples on
B:collection stores the individual occurrences of the element, the sub-interface set element is unique, and the sub-interface list element is repeatable. Bachelor
(3) Map interface Features Overview
A: Add Features
B: Delete Feature
C: Judging function
D: Get Features
E: Length function
(4) Traversal of the Map collection
A: Key to find the value
A: Gets the collection of all keys
B: Iterate through the collection of keys to get each key
C: Find the value according to the key to the collection
B: Key-value pair object find key and value
A: Gets the collection of all key-value pairs of objects
B: Iterates over the collection of key-value pairs of objects, getting each key-value pair of objects
C: To get keys and values based on the key value of the object
(traversal) Code embodies:
Map<string,string> HM = new hashmap<string,string> ();
Hm.put ("a002", "Hello");
Hm.put ("a003", "World");
Hm.put ("a001", "Java");
Mode 1 Key Find value
set<string> set = Hm.keyset ();
for (String key:set) {//Enhanced for
String value = Hm.get (key);
System.out.println (key+ "---" +value);
}
Type 2 key value to the object to find the key and value: this in the servlet to write the purchase product program is a template code
Set<map.entry<string,string>> Set2 = Hm.entryset ();
for (map.entry<string,string> Me:set2) {
String key = Me.getkey ();
String value = Me.getvalue ();
System.out.println (key+ "---" +value);
}
(5) HashMap Collection of Exercises
A:hashmap<string,string>
B:hashmap<integer,string>
C:hashmap<string,student>
D:hashmap<student,string>
(6) TreeMap Collection of Exercises
A:treemap<string,string>
B:treemap<student,string>
(v). Data structures that are common in collections:
ARRAYXXX: The underlying data structure is an array, query fast, and delete slowly
LINKEDXXX: The underlying data structure is linked list, query slow, and delete quickly
HASHXXX: The underlying data structure is a hash table. Dependent on two methods: Hashcode () and Equals ()
TREEXXX: The underlying data structure is a two-fork tree. Sort by two ways: natural sort and comparator sort
(vi).: Collections
(1) is a tool class that operates on a collection
(2) Question: What is the difference between collection and collections?
(i): Collection is the top-level interface for single-column collections, with two sub-interfaces list and set
(ii): Collections is a tool class that operates on collections, can sort and find collections, and so on
(3) Common several small methods:
(i): public static <T> void sort (list<t> List)
(ii): public static <T> int BinarySearch (list<?> list,t key)
(iii): public static <T> T Max (collection<?> coll)
(IIII):p ublic static void reverse (list<?> List)
(IIIII):p ublic static void Shuffle (List<?> List)
(4) Case
(i): ArrayList collection stores the ordering of custom objects
(ii): Simulated bucket landlord shuffle and licensing
(iii): Simulation of bucket landlord shuffle and licensing and sorting cards
Summary of the collection framework for Java basics