Original URL: http://kings11347.blog.163.com/blog/static/56047032201212895416436/
Import Java.util.HashMap;
Import Java.util.Iterator;
Import Java.util.Set;
Import Java.util.Map.Entry;
public class Hashmapuse {
public static void Main (string[] args) {
hashmap<string, string> HashMap = new hashmap<string, string> ();
Hashmap.put ("cn", "China");
Hashmap.put ("Us", "Mi Guo");
Hashmap.put ("en", "United Kingdom");
System.out.println (HASHMAP);
SYSTEM.OUT.PRINTLN ("cn" +hashmap.get ("cn"));
System.out.println (Hashmap.containskey ("cn"));
System.out.println (Hashmap.keyset ());
System.out.println (Hashmap.isempty ());
Hashmap.remove ("cn");
System.out.println (Hashmap.containskey ("cn"));
Traversing HashMap with iterator
Iterator it = Hashmap.keyset (). Iterator ();
while (It.hasnext ()) {
String key = (string) it.next ();
System.out.println ("key:" +key);
System.out.println ("Value:" +hashmap.get (key));
}
Traversing HashMap with entry
set<entry<string, string>> sets = Hashmap.entryset ();
for (entry<string,string> entry:sets) {
System.out.println (Entry.getkey () + ",");
System.out.println (Entry.getvalue ());
}
}
}
"Go" [Java] hashmap examples of use