Introducing the Map.entry interface

Source: Internet
Author: User

The map is an interface in Java, and Map.entry is an internal interface to the map. The Java.util.Map.Entry interface is mostly used when traversing a Map .

Map provides some common methods, such as KeySet (), EntrySet (), and so on , the KeySet () method return value is a collection of key values in map, and the return value of EntrySet () returns a set collection of type Map.entry.

Map.entry is an internal interface to the map declaration, which is generic and defined as entry<k,v>. It represents an entity (a Key-value pair) in a map. The interface has a getkey (), GetValue method.

 Packagetest;ImportJava.util.*;ImportJava.util.Map.Entry; Public classB { Public Static voidMain (string[] args) {Map<Integer,Integer> mm =NewHashmap<integer,integer>();  for(inti=0;i<10;i++) {Mm.put (I, I); }            for(Entry<integer, integer>E:mm.entryset ()) {System.out.println ("Key:" +E.getkey ()); System.out.println ("Value:" +E.getvalue ()); }            for(Iterator<entry<integer, integer>> i =Mm.entryset (). iterator (); I.hasnext ();) {Entry<integer, integer> e =I.next (); System.out.println ("Key:" +E.getkey ()); System.out.println ("Value:" +E.getvalue ()); }        }   49}

Introducing the Map.entry interface

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.