1 Packagecn.itcast_01;2 3 ImportJava.util.HashMap;4 ImportJava.util.Map;5 ImportJava.util.Set;6 7 /*8 * Traversal of the map collection. 9 * Map--CouplesTen * One * Ideas: A * A: Get a collection of all marriage certificates - * B: Walk through the collection of marriage certificates, get every marriage certificate - * C: Obtain husband and wife according to marriage certificate the * - * Conversion: - * A: Gets the collection of all key-value pairs of objects - * B: Iterate over the collection of key-value pairs of objects and get each key-value pair of objects + * C: Gets the key and value for the object based on the key value - * + * The most troublesome thing about this is how does the key value represent the object? A * Look at one of the ways we started: at * set<map.entry<k,v>> entryset (): Returns a collection of key-value pairs of objects - */ - Public classMapDemo4 { - Public Static voidMain (string[] args) { - //To create a collection object -map<string, string> map =NewHashmap<string, string>(); in - //Create an element and add it to the collection toMap.put ("Yang", "Little Dragon Girl")); +Map.put ("Guo Jing", "Huang Rong"); -Map.put ("Yang Kang", "Munians"); theMap.put ("Chen Xuanfeng", "MUI Wind"); * $ //gets the collection of all key-value pairs of objectsPanax NotoginsengSet<map.entry<string, string>> set =Map.entryset (); - //iterates over the collection of key-value pairs of objects, getting each key-value pair of objects the for(Map.entry<string, string>Me:set) { + //get keys and values on objects based on key values AString key =Me.getkey (); theString value =Me.getvalue (); +SYSTEM.OUT.PRINTLN (key + "---" +value); - } $ } $}
Android (Java) Learning note 105:map The collection's traversal key value on the object to find the key and value