Use EntrySet loops for map in Java

Source: Internet
Author: User

Based on the new features of JDK5, use a for loop map, such as the Key for loop map

123 for(String dataKey : paraMap.keySet())   {      System.out.println(dataKey );             }

Note how paramap is defined, if it is a simple map paramap = new HashMap (); The string in front can only be converted to object.

The key and value of the entire map

123456789101112 Map<Integer,String> map = new LinkedHashMap<Integer,String>();map.put(1"星期一");map.put(2"星期二");map.put(3"星期三");map.put(4"星期四");map.put(5"星期五");map.put(6"星期六");map.put(7"星期日");for(Map.Entry<Integer, String> entry: map.entrySet()) { System.out.print(entry.getKey() + ":"+ entry.getValue() + "\t");}

Outputs:

1: Monday 2: Tuesday 3: Wednesday 4: Thursday 5: Friday 6: Saturday 7: Sunday

Use EntrySet loops for map in Java

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.