One.
The method is explained, and a demonstration is done.
Create an object in the main function, here is the map reference, (why do you do it by method?). )。 Map has generics, what type of map do you want to manipulate?
Writing a school number and name is a mapping relationship. To figure out, what is the difference between a map set and a collection, and when does it work? This is the most important, the method is finished to know.
The number is an integer type, which means that the int type is hung and a packet is directed.
In method methods, adding elements to the Map collection is the use of the Put method. The Put method will have a return value. Create the Map object in the main function, and then call the method methods.
What type of new map object do you want to use here? (Is it because the map is an interface, to find the following sub-class to operate?) )
Looking for a suitable subclass to use as the type of the new map object, the subclasses often used are several, such as HashMap,
After using HashMap, the result is correct.
Collectin is a single-column collection, and map is a double-row collection. Print the collection and get the keys and values. Connect with an equal sign, indicating that it has a relationship.
For the result of the above operation, there are a few comments, the same key, the value will be overwritten.
Next, store a few more. The output display is unordered. Do not mean that 2,7,8 is orderly, hashmap is also a hash table, the integer method and the hash table is the same way.
the next demonstration is the Delete method, in the Map collection, the corresponding key value is deleted, the value returned.
Here is the judgment, and the result returns ture.
Finally, the method is obtained and the result is Xiaoqiang. Preserves the corresponding key-value pairs in the collection. If you enter a key that does not exist, the return is null.
Java-preliminary Understanding-Common Object API (collection framework-common method Demo)