* Mapping Table
* Java Class Library provides two common implementations of HashMap and treemap for a mapping table
* HashMap hashes the keys, treemap the elements in the overall order of the keys, and constructs them into a search tree
*
* Similar to set, HashMap is faster than treemap, and does not need to be accessed by arrangement, but should also be selected HashMap
* Note that the value of the key must be unique, if a second put has the same key value in, the second value will replace the first value, put will
* Returns the previous value stored with this key parameter
*
* We can get a view of the map, which is a set of views that implement the collection interface object, or its sub-interfaces
* There are 3 views, respectively
* Key set, value set (simple set, not set), key/value pair Set. The key and the Key/value form a set, because a key in the map
* Only one copy is allowed
*
* The following three methods return the 3 views previously described
* set<k> KeySet () (keySet does not belong to HashSet and treeset, but objects that implement some other class of the Set Interface)
* Collection<v> Values ()
* set<map<key, value>> EntrySet ()
*
* You cannot add elements to the view of a keyset because it is meaningless to simply add a key.
* EntrySet also has the same limitations, but conceptually, adding new key/value pairs is meaningful
Example
1 public Static voidmain (string[] Args) {2 3map<string, employee> staff=NewHashmap<>();4Staff.put ("144-25-5464",NewEmployee ("Amy Lee"));5Staff.put ("576-24-2546",NewEmployee ("Harry hacker"));6Staff.put ("334-45-5174",NewEmployee ("Gary Cooper"));7Staff.put ("124-75-0174",NewEmployee ("francesca Cruz"));8 9 System.out.println (staff);Ten oneStaff.remove ("576-24-2546"); a -Staff.put ("124-75-0174",NewEmployee ("new Francesca Cruz")); - theSystem.out.println (staff.get ("334-45-5174")); - - //Iterative Access - for(map.entry<string, employee>Entry:staff.entrySet ()) { +String key =Entry.getkey (); -Employee value =Entry.getvalue (); +System.out.println ("key=" +key+ ", value" +value); a } at}
Initial knowledge of the Java collection--mapping table (map)