Nesting of Java 18-8 HashMap and ArrayList 2

Source: Internet
Author: User

Data chaos.
Results:
Novel
Three great masterpieces
Three kingdoms
LV BU 30
Zhao Yun 28
Journey
Monkey King 600
Tang Monk 30
Martial arts
Laughing and proud of the lake
Make the Fox Punch 26
林平 of 28
The Statue of God
Guo Jing 40
Yang over 23


Analysis:
The total set is hashmap<string,hashmap<string,arraylist<person>>>
Subset:hashmap<string,arraylist<person>> arraylist<person>

1  PackageZl_mapdemo;2 3 Importjava.util.ArrayList;4 ImportJava.util.HashMap;5 ImportJava.util.Set;6  Public classHashmapdemo {7 8      Public Static voidMain (string[] args) {9         Ten         //Create a total collection of novels OneHashmap<string,hashmap<string,arraylist<person>>> HM1 = A                 NewHashmap<string,hashmap<string,arraylist<person>>>(); -          -         //create three great masterpieces subset theHashmap<string,arraylist<person>> HM2 =NewHashmap<string,arraylist<person>>(); -         //Create Kingdoms Collection -Arraylist<person> List1 =NewArraylist<person>(); -         //Create a Journey to a collection +Arraylist<person> List2 =NewArraylist<person>(); -          +         //creating elements for the kingdoms and the Journey collection Aperson P1 =NewPerson ("LV bu", 30); atperson P2 =NewPerson ("Zhao Yun", 28); -Person P3 =NewPerson ("Monkey King", 600); -Person P4 =NewPerson ("Tang priest", 26); -          -         //add elements to the kingdoms and Journey to the collection - List1.add (p1); in List1.add (p2); - List2.add (p3); to List2.add (p4); +          -         //Add the kingdoms and the journey to the three great collections theHm2.put ("Kingdoms", list1); *Hm2.put ("Journey to the Monkey", list2); $         Panax Notoginseng         //and add the three great masterpieces to the collection of novels. -Hm1.put ("The Three great classics", HM2); the          +         //Create a martial arts collection AHashmap<string,arraylist<person>> Wxhm =NewHashmap<string,arraylist<person>>(); the          +         //create a collection of laughing and the Gods and the Condor -arraylist<person> array1 =NewArraylist<person>(); $Arraylist<person> array2 =NewArraylist<person>(); $  -         //create the elements of the collection of the Laughing Pride and the Condor -person S1 =NewPerson ("Make Fox Punch", 26); thePerson S2 =NewPerson ("林平", 28); -Person S3 =NewPerson ("Guo Jing", 40);WuyiPerson S4 =NewPerson ("Yang over", 23); the          -         //add these elements to each of the two sets Wu Array1.add (S1); - array1.add (S2); About Array2.add (S3); $ Array2.add (S4); -          -         //add two collections to a martial arts fiction collection -Wxhm.put ("The Pride of the lake", array1); AWxhm.put ("The Condor Man", array2); +          the         //Add a collection of martial arts novels to the collection -Hm1.put ("Martial arts Fiction", WXHM); $          the         //Traverse the          the         //get a collection of keys for a novel collection theSet<string> Hm1set =Hm1.keyset (); -         //Traverse in          for(String hm1key:hm1set) { the             //the value of the novel collection is Hashmap<string,arraylist<person>> theHashmap<string,arraylist<person>> xsvalue=Hm1.get (hm1key); About             //create three masterpieces and martial arts novels The key collection for this collection theSet<string> Xsset =Xsvalue.keyset (); the             //Traverse the              for(String xskey:xsset) { + System.out.println (xskey); -             //The value of this collection is arraylist<person> theArraylist<person> value =Xsvalue.get (xskey);Bayi              the             //traversing the ArrayList collection the              for(person Result:value) { -System.out.println ("\ T" +result.getname () + "\ T" +result.getage ()); -             } the         } the         } the     } the  -}

Nesting of Java 18-8 HashMap and ArrayList 2

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.