1:map (Master)
Map Interface Overview
Object that maps a key to a value
A map cannot contain duplicate keys
Each key can be mapped to at most one value
the difference between the map interface and the collection interface
Map is a double row, collection is a single row
The key of the map is unique, and the collection sub-system set is unique.
Data structure values for the map collectionValid for keys, regardless of value
The data structure of the collection collection isValid for element
(3) Map interface Function overview (self-completion)
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
The code reflects:
Map<string,string> HM = new hashmap<string,string> ();
Hm.put ("it002", "Hello");
Hm.put ("it003", "World");
Hm.put ("it001", "Java");
Mode 1 Key Find value
set<string> set = Hm.keyset ();
for (String Key:set) {
String value = Hm.get (key);
System.out.println (key+ "---" +value);
}
Method 2 Key value to object find key and value
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>
(7) Case
A: Count the occurrences of each character in a string
B: Nested traversal of a collection
A:hashmap Nesting HashMap
B:hashmap nesting ArrayList
C:arraylist Nesting HashMap
D: Multilayer Nesting
2:collections (understanding)
(1) is a tool class that operates on a collection
(2) Interview questions: The difference between collection and collections
A:collection is the top-level interface of a single-column collection with two sub-interfaces list and set
B:collections is a tool class that operates on a collection and can be sorted and looked up
(3) Common several small methods:
A:public static <T> void sort (list<t> List)
b:public static <T> int BinarySearch (list<?> list,t key)
C:public static <T> T max (collection<?> coll)
D:public static void reverse (list<?> List)
E:public static void Shuffle (List<?> List)
(4) Case
A:arraylist Collection stores the ordering of custom objects
B: Simulated bucket landlord shuffle and licensing
C: Simulate bucket landlord shuffle and licensing and sort cards
Re-stepping on Java Road _day18 (map,collections)