1. HashMap nested HashMap
Wisdom Podcast
JC Basic Class
Chenyu Building 20
Gao Yue 22
JY Employment Class
Li Jie 21
Cao Shilei 23
The elements are stored first, and then the elements are traversed
2. code example:
1 Packagecn.itcast_05;2 3 ImportJava.util.HashMap;4 ImportJava.util.Set;5 6 /*7 * HashMap nested HashMap8 * 9 * Preach Intelligence podcastTen * JC Basic class One * Chenyu Building A * Gao Yue - * JY Employment class - * Li Jie the * Cao Shilei - * - * Store elements first, then iterate over elements - */ + Public classHashMapDemo2 { - Public Static voidMain (string[] args) { + //To create a collection object AHashmap<string, hashmap<string, integer>> czbkmap =NewHashmap<string, Hashmap<string, integer>>(); at - //Create a base class collection Object -hashmap<string, integer> jcmap =NewHashmap<string, integer>(); - //adding elements -Jcmap.put ("Chenyu building", 20); -Jcmap.put ("High jump", 22); in //add basic classes to a large collection -Czbkmap.put ("JC", jcmap); to + //Create an Employment class collection Object -hashmap<string, integer> jymap =NewHashmap<string, integer>(); the //adding elements *Jymap.put ("Li Jie", 21); $Jymap.put ("Cao Shilei", 23);Panax Notoginseng //add basic classes to a large collection -Czbkmap.put ("JY", jymap); the + //iterating through the collection ASet<string> Czbkmapset =Czbkmap.keyset (); the for(String czbkmapkey:czbkmapset) { + System.out.println (czbkmapkey); -hashmap<string, integer> czbkmapvalue =Czbkmap.get (czbkmapkey); $Set<string> Czbkmapvalueset =Czbkmapvalue.keyset (); $ for(String czbkmapvaluekey:czbkmapvalueset) { -Integer Czbkmapvaluevalue =Czbkmapvalue.get (czbkmapvaluekey); -System.out.println ("\ T" +czbkmapvaluekey+ "---" +czbkmapvaluevalue); the } - }Wuyi } the}
Run the effect as follows:
Java basic Knowledge Hardening Collection Framework note 62:map collection HashMap nested HashMap