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);
            }
    
    
        }
    }

    运行结果:

  • 相关阅读:
    php apc缓存以及与redis的对比
    React Refs
    React 表单与事件
    React AJAX
    React 组件生命周期
    React 组件 API
    React Props
    React State(状态)
    react 组件之间传值
    react 创建组件
  • 原文地址:https://www.cnblogs.com/bichen-01/p/14363602.html
Copyright © 2011-2022 走看看