1 Packagecn.itcast_01;2 3 Importjava.util.Collection;4 ImportJava.util.HashMap;5 ImportJava.util.Map;6 ImportJava.util.Set;7 8 /*9 * Get Features:Ten * V get (Object key): Gets the value according to the key One * set<k> keySet (): Gets the collection of all the keys in the collection A * collection<v> values (): Gets the collection of all values in the collection - */ - Public classMapDemo2 { the Public Static voidMain (string[] args) { - //To create a collection object -map<string, string> map =NewHashmap<string, string>(); - + //creating elements and adding elements -Map.put ("Deng Chao", "Sun Li"); +Map.put ("Huang Xiaoming", "Angelababy yang"); AMap.put ("Jay Chou", "Jolin Tsai")); atMap.put ("Jacky Lau Wei", "Yang Mi"); - - //V get (Object key): Gets the value based on the key -System.out.println ("Get:" + map.get ("Jay Chou"))); -System.out.println ("Get:" + map.get ("Zhou Jie"));//returns null -System.out.println ("----------------------"); in - //set<k> KeySet (): Gets the collection of all the keys in the collection toSet<string> set =Map.keyset (); + for(String key:set) { - System.out.println (key); the } *System.out.println ("----------------------"); $ Panax Notoginseng //collection<v> values (): Gets a collection of all values in the collection -collection<string> con =map.values (); the for(String value:con) { + System.out.println (value); A } the } +}
Get features for Android (Java) Learning notes 103:map Collection