Nesting of sets

The code is as follows:

import java. util. HashMap; import java. util. Map; import java. util. Set; import java. util. Iterator; /* Nesting of map set, the map set is still stored in the map * requirements: * intelligence podcast * java basic class: 001 Zhang San * 002 Li Si * Java employment class: 001 Wang Wu * 002 Zhao Liu * basic class map < student number, name > * employment class map < student number, name > * intelligence podcast map < class name, Basic class map > * / public class mapmapdemo {public static void main (string [] args) {/ / define the basic class set HashMap < string, string > javase = new HashMap < string, string > (); / / define the employment class set HashMap < string, string > JavaEE = new HashMap < string, string > (); / / store the student information in the class set javase.put ("001", "Zhang San"); javase.put ("002", "Li Si") ; javaee. Put ("001", "Wang Wu"); javaee. Put ("002", "Zhao Liu")// Define a collection container. The key is the class name, and the value is two class containers. HashMap < string, HashMap < string, string > > czbk = new HashMap < string, string > > (); czbk. Put ("basic class", javase); czbk. Put ("employment class", JavaEE); keySet(czbk); entrySet(czbk); } // Traverse the public static void keyset (HashMap < string, string > > czbk) {/ / call the czbk collection method keyset to store the keys in the set set set < string > classnameset = czbk. Keyset(); / / iterate the set set iterator < string > classnameit = classnameset. Iterator(); while (classnameit. Hasnext()) {/ / classnameit.next obtains the set set element. The key of czbk set string classnamekey = classnameit. Next(); / / the method get of czbk set obtains the value. The value is a HashMap set. HashMap < string, string > classmap = czbk. Get (classnamekey); / / call the classmap set method keyset, and the key is stored in the set set set set set < string > studentnum = classmap. Keyset() ; Iterator
studentIt=studentNum. iterator(); While (studentit. Hasnext()) {/ / studentit.next obtains the key of classmap, student number string numkey = studentit. Next(); / / call the get method in the classmap collection to obtain the value string namevalue = classmap.get (numkey); system.out.println (classnamekey + "..."+ numKey+"..."+ nameValue); } } } Public static void entryset (HashMap < string, string > > czbk) {/ / call the czbk collection method entryset method to store the key value pair relationship object of czbk collection in the set set set set set < map. Entry < string, string > > > classnameset = czbk. Entryset(); system. Out. Println ("================================================================================= ; // Iterator iterates set iterator < map Entry

>> classNameIt=classNameSet. iterator(); While (classnameit. Hasnext()) {/ / classnameit. Next method, which takes out the key value pairs of czbk set, relational object map. Entry < string, string > > classnameentry = classnameit. Next(); / / classnameentry method getKey, getValue string, classnamekey = classnameentry. Getkey(); / / get the value, which is a map set HashMap < string, string > classmap = classnameentry. Getvalue() ; // Call the class set classmap method entryset, and store the key value pair relation object set < map Entry

> studentSet=classMap. entrySet(); // Iterate set iterator < map Entry

> studentIt=studentSet. iterator(); While (studentit. Hasnext()) {/ / studentit method next gets the key value pair relation object of class collection map. Entry < string, string > studentit = studentit. Next(); / / studentit method getKey and getValue string numkey = studentit. Getkey(); string namevalue = studentit. Getvalue(); system. Out. Println (classnamekey + "..."+ numKey+"..."+ nameValue); } } } }



The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>