Nesting of Java 18-9 HashMap and ArrayList 3

Source: Internet
Author: User

ArrayList collection nested HashMap set merge traversal.
Demand:
Assume that the elements of the ArrayList collection are hashmap. There are 3 of them.
The keys and values of each HashMap collection are strings.
The elements are as follows, please traverse.
Results:
Zhou Yu---little Joe
Bu---marten cicada

Guo Jing---huang Rong
Yang---little dragon girl.

Make the FOX flush---
林平 's---Keilingshan

1  PackageZl_mapdemo;2 3 Importjava.util.ArrayList;4 ImportJava.util.HashMap;5 ImportJava.util.Set;6  Public classMapandhashmap {7 8      Public Static voidMain (string[] args) {9         Ten         //Create a total collection first ArrayList OneArrayList <HashMap> list =NewArrayList <HashMap>(); A          -         //Create the first collection element -Hashmap<string,string> HM1 =NewHashmap<string,string>(); the          -         //add elements to this collection -Hm1.put ("Zhou Yu", "Little Joe")); -Hm1.put ("Lv bu", "Marten Cicada"); +          -          +         //Create a second collection element AHashmap<string,string> HM2 =NewHashmap<string,string>(); at          -         //add elements to this collection -Hm2.put ("Guo Jing", "Huang Rong"); -Hm2.put ("Yang", "Little Dragon Girl")); -          -         //Create a third collection element inHashmap<string,string> hm3 =NewHashmap<string,string>(); -          to         //add elements to this collection +Hm3.put ("Make Fox Chong", "Ren Ying"); -Hm3.put ("林平", "Keilingshan"); the          *         //Add the above 3 small collections to the total collection $ List.add (HM1);Panax Notoginseng List.add (HM2); - List.add (HM3); the          +         //traversal of the total collection A          for(hashmap<string,string>listkey:list) { the             //iterate over subsets of HashMap collections +             //Get Key Collection -Set <String> HashSet =Listkey.keyset (); $             //traversing the HashSet collection $              for(String hashkey:hashset) { -                 //Get Value -String result =Listkey.get (hashkey); theSystem.out.println (hashkey+ "\ T" +result); -             }Wuyi              the         } -     } Wu  -}

Nesting of Java 18-9 HashMap and ArrayList 3

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.