Android (Java) Learning note 105:map The collection's traversal key value on the object to find the key and value

Source: Internet
Author: User

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

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.