The entryset of a good way to traverse map in Java

Source: Internet
Author: User

There are various map1 in Java, and one of the most efficient traversal methods is as follows:


treemap<string,long> map = new treemap<string,long> (); Entry<string long> Peek; The handle of this type can only point to a key value pair in map//If the generic type is indicated, then the corresponding type is returned directly below, and no person returns an object iterator<entry<string,long>>     it = Uploads.entryset (). iterator ();//The generic type here indicates the data type to traverse while (It.hasnext ()) {peek = It.next ();     System.out.println (Peek.getkey ());  System.out.println (Peek.getvalue ()); }

Or

treemap<string,long> map = new treemap<string,long> (); for (entry<string,long> Entry:map.entyrSet ()      ) {System.out.println (Entry.getkey ()); System.out.println (Entry.getvalue ());}



This use of the EntrySet traversal method is less complex than using keyset with use.

This article is from the "Science-mymind" blog, make sure to keep this source http://qkkcoolmax.blog.51cto.com/8843422/1615010

The entryset of a good way to traverse map in Java

Related Article

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.