Today using the key-value pairs, and then think of the Java Map, because it was not very familiar with, looked at the following source code, as follows:
/** Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. * ORACLE proprietary/confidential. Use are subject to license terms. */ PackageJava.util; Public InterfaceMap<k,v> { //Query Operations intsize (); BooleanIsEmpty (); BooleanContainsKey (Object key); BooleanContainsvalue (Object value); V get (Object key); //modification Operationsv put (K key, v value); V Remove (Object key); //Bulk Operations voidPutall (map<?extendsK?extendsV>m); voidClear (); // viewsSet<k>KeySet (); Collection<V>values (); Set<map.entry<k, v>>EntrySet (); InterfaceEntry<k,v>{K getKey (); V GetValue (); V SetValue (v value); Booleanequals (Object O); inthashcode (); } //Comparison and hashing Booleanequals (Object O); inthashcode ();}
PS: It is clear that the map is an interface, and HashMap is a class that implements the map interface. And I think the source code is very beautiful! You should look more later.
version:jdk1.7.0_79
MAP traversal, sample code:
Iterator entries = ReadFile.map.entrySet (). Iterator (); while (Entries.hasnext ()) { = (map.entry) Entries.next (); = (String) Entry.getkey (); = (String) entry.getvalue (); System.out.print ("key:" + key + "," + "value:" + value + "\ n");}
Reference: Simple use of map,set in Java
"Java" Map