Java traversal Map

Source: Internet
Author: User
// The most common Traversal method. The most common method is the most commonly used method. Although it is not complex, it is very important. This is what we are most familiar with. I will not talk about it much !! Public static void work (Map <string, student> map) {collection <student> C = map. values (); iterator it = C. iterator (); For (; it. hasnext ();) {system. out. println (it. next () ;}/// use keyset for traversal. The advantage of this function is that you can set the value of the desired value based on the key, making it more flexible !! Public static void workbykeyset (Map <string, student> map) {set <string> key = map. keyset (); For (iterator it = key. iterator (); it. hasnext ();) {string S = (string) it. next (); system. out. println (map. get (s) ;}/// a more complex Traversal method ~~ He is very violent. He is so flexible that he can get whatever he wants ~~ Public static void workbyentry (Map <string, student> map) {set <map. entry <string, student> set = map. entryset (); For (iterator <map. entry <string, student> it = set. iterator (); it. hasnext ();) {map. entry <string, student> entry = (map. entry <string, student>) it. next (); system. out. println (entry. getkey () + "--->" + entry. getvalue ());}}}

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.