Java-map.entry

Source: Internet
Author: User

The map is an interface in Java, and Map.entry is an internal interface to the map.

Map provides a number of common methods, such as keyset (), EntrySet (), and so on.

The KeySet () method return value is a collection of key values in map; The return value of EntrySet () also 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.

 ImportJava.util.HashMap;ImportJava.util.Iterator;ImportJava.util.Map.Entry;ImportJava.util.Map;  Public classHello { Public Static voidMain (string[] args) {hashmaptest ();} Public Static voidhashmaptest () {System.out.println ("----------------hashmaptest---------------"); Map<String,String> Map1 =NewHashmap<string,string>(); Map1.put ("1", "A"); Map1.put ("2", "B"); Map1.put ("3", "C"); Map1.put ("4", "D"); Map1.put ("5", "E"); Map1.put ("6", "F"); Iterator<entry<string, string>> it =Map1.entryset (). iterator (); while(It.hasnext ()) {Map.entry<String,String> e = (map.entry<string,string>) It.next (); System.out.println (E.getkey ()+ ":" +E.getvalue ()); } System.out.println (MAP1);}}

Java-map.entry

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.