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