Java Basic Knowledge Enhancement Collection Framework note 62:map set HashMap nesting HashMap

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.