-------------------| The data stored in the MAP is in the form of key-value pairs, the keys are not repeatable, and the values are repeatable.
----------------------------| HashMap
----------------------------| TreeMap
----------------------------| HashTable
Map interface methods:
Add to:
Put (K key, V value)
Putall (map<? extends K,? extends v> m)
Delete
Remove (Object key)
Clear ()
Get:
Get (Object key)
Size ()
Judge:
ContainsKey (Object key)
Containsvalue (Object value)
IsEmpty ()
ImportJava.util.*; Public classex12 { Public Static voidMain (string[] args) {Map<string, string> map =NewHashmap<string, string> ();//Why did you change to int ?Map.put ("Tom", "1"); Map.put ("Jack", "2"); Map.put ("Yoo", "3"); Map.put ("Peter", "4"); Map.put ("LiLi", "5"); SYSTEM.OUT.PRINTLN (map); System.out.println (); Map<string, string> map2 =NewHashmap<string,string>(); Map2.put ("AAAAA", "1"); Map2.put ("Ppppp", "6"); Map.putall (MAP2);//Add all of the MAP2 to the map collectionSYSTEM.OUT.PRINTLN (map);//Note the result of the row outputSystem.out.println (); System.out.println ("Remove (Object key) =====" + map2.remove ("AAAAA"));//Note the return valueSystem.out.println ("Remove (Object key) =====" + map2.remove ("bbbbb")); System.out.println (); //System.out.println ("Clear () =======" + map2.clear ());//Errormap2.clear (); System.out.println (MAP2);//Clear AllSystem.out.println (); System.out.println (Map.get ("PPPPP")); System.out.println (Map.size ()); System.out.println (); System.out.println (Map.isempty ()); }}
Java Collection (MAP)