The key is only to know the student number, through the study number to find the name
Key Value
School Number 1 Name 1
School Number 2 Name 2
School Number 3 Name 3
Study number 1 (duplicate key) name 4
Java for this technique----->map collection, a collection of key-value mappings (interfaces)
The 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.
Map<k,v>, in the map collection, only valid for keys, not value-independent
2)
Features of the Map interface:
V put (K key,v value): Add function: Associates the specified value and key
If the current key is stored once, the return value is null
If it is not the first time, the return value is the first corresponding value, and the current value replaces the value corresponding to the previous key!
获取功能
Boolean IsEmpty (): Determines whether the mapping relationship is empty
3) Two methods of traversal
1, this kind of traversal method is often used in the actual development ...
Set<k> KeySet (): Gets the collection of all the keys in the mapping relationship
V get (Object key): Find value by key
Conversion method:
1) Bring all the husbands together.
2) Let the husband its corresponding wife
3) to traverse them out
Another way of the map collection is to traverse set<map.entry<k,v>> entryset (): It is related to the traversal of the map collection (key-value pairs object)
Forwarding method: 1) Get all marriage license 2) find the corresponding husband and wife by marriage certificate 3) Traverse output
Idea: 1) Get all the key value objects EntrySet ()
2) K GetKey () and V GetValue (), gets the key values for each key and each value in the object
3) Traversal
Ideas:
1) Gets the collection of all the keys
2) find its corresponding value by key
3) Traverse can
(6) Set set
1) What is the difference between a set set and a list set?
Set collection: element repetition is not allowed, unique (element can be null), no guaranteed sequence of iterations (underlying hash table and Hascode)
Unordered (store and remove inconsistencies)
2) The Add method of the HashSet collection relies on the two-column set HashMap, which relies on two methods, the Hashcode () method, and the Equals () method
Compare the Hashcode () code value of the string first, and then compare the Equals () method
If the Hascode code value is the same, the content is also compared, because the string is stored, overriding the Equals () method
The string itself overrides the Equals method, so no more rewriting is required!
3) The custom class is not rewritten in the hashcode () and Equals () methods, both of which resolve, overriding both methods
(iii) new features after JDK5
New features after Jdk5:
Enhanced for, static import, variable parameters, generics, auto-unboxing.
(1) Variable parameter: When the parameter number of a method is indeterminate, use a variable parameter
Format:
Modifier returns a value type method name (data type ... Variable name) {...}
Attention:
1) Variable name: as an array
2) When using the data type ...
Note: According to the specific needs to complete, the general situation, know that this feature can be
(2) Enhanced for
Enhance the format of a for loop
For (data large type variable name: Array or Collection object name) {
Output variable can!
}
Enhanced for occurs when an iterator is substituted, so you can use the enhanced for to go through the collection or iterate through the array
The disadvantage of enhancing A For loop: If the object of the collection is NULL, an exception will occur if the collection operation is again
To judge a set, to solve a non-null judgment
(3) Static import
Characteristics:
1) The premise is that the method must be static
2) The level of a method to import to
Format for static import: