zoukankan      html  css  js  c++  java
  • Map集合遍历之第二种方法(键值对)

     “键值对“的方式遍历,更加面向对象的方式,代码复杂。

    案例:

    package com.itheima.Map复习;
    
    import java.util.*;
    
    /**
     * @program: javaDemo01->MapTestDemo01
     * @description: Map遍历复习
     * @author: 安生
     * @create: 2021-02-02 17:25
     **/
    public class MapTestDemo01 {
        private static final Map<String,Integer> ALL_PROPLE = new HashMap<>();
    
        static {
           ALL_PROPLE.put("陈平安",16);
           ALL_PROPLE.put("阿良",18);
           ALL_PROPLE.put("齐静春",16);
    //        System.out.println(ALL_PROPLE);
        }
        public static void main(String[] args) {
            /**
             * 第二种遍历方式 "键值对"
             */
            Set<Map.Entry<String, Integer>> entries = ALL_PROPLE.entrySet();
            for (Map.Entry<String, Integer> entry : entries) {
                String key = entry.getKey();
                Integer value = entry.getValue();
                System.out.println(key + "=>" + value);
            }
    
            //快捷方式 直接 ALL_PEOPLE.entrySet.for
            for (Map.Entry<String, Integer> stringIntegerEntry : ALL_PROPLE.entrySet()) {
                String key = stringIntegerEntry.getKey();
                Integer value = stringIntegerEntry.getValue();
                System.out.println(key + "=>" + value);
            }
    
    
        }
    }

    运行结果:

  • 相关阅读:
    属性包装
    生成器
    迭代器
    深拷贝-浅拷贝
    装饰器-wrapper
    类别不均衡
    参数优化-学习曲线
    参数优化-验证曲线
    参数优化-API
    D. Number Of Permutations 符合条件的排列种类
  • 原文地址:https://www.cnblogs.com/bichen-01/p/14363602.html
Copyright © 2011-2022 走看看