zoukankan      html  css  js  c++  java
  • Map 的遍历

    一、Map的遍历

      在后面java的开发过程中会遇到Map类的使用,然而map的遍历是一大问题。

      Map遍历用两种比较交代的方法:

    package edu.map;
    
    import java.util.HashMap;
    import java.util.Map;
    import java.util.Map.Entry;
    import java.util.Set;
    
    public class MapTest {
    
    public static void main(String[] args) {
    Map<String, String> map = new HashMap<String, String>();
    map.put("name", "dave");
    map.put("password", "123456");
    map.put("address", "CQUPT");
    // 方法一
    Set<String> set = map.keySet();
    for (String key : set) {
    System.out.println(key + ":" + map.get(key));
    }
    // 方法二
    Set<Entry<String, String>> set2 = map.entrySet();
    for (Entry<String, String> entry : set2) {
    System.out.println(entry);
    }
    }
    }
  • 相关阅读:
    盘子序列
    最大矩形面积
    【模板】ST表
    排队
    map循环遍历
    vue循环遍历给div添加id
    正则 匹配
    字符串拼接
    js对象追加到数组里
    二级标题左侧加粗线条
  • 原文地址:https://www.cnblogs.com/googlemeoften/p/4827621.html
Copyright © 2011-2022 走看看