zoukankan      html  css  js  c++  java
  • (备忘)Java Map 遍历

      //最常规的一种遍历方法,最常规就是最常用的,虽然不复杂,但很重要,这是我们最熟悉的,就不多说了!!
    public static void work(Map<String, Student> map) {
    Collection<Student> c = map.values();
    Iterator it = c.iterator();
    for (; it.hasNext();) {
    System.out.println(it.next());
    }
    }
      //利用keyset进行遍历,它的优点在于可以根据你所想要的key值得到你想要的 values,更具灵活性!!
    public static void workByKeySet(Map<String, Student> map) {
    Set<String> key = map.keySet();
    for (Iterator it = key.iterator(); it.hasNext();) {
    String s = (String) it.next();
    System.out.println(map.get(s));
    }
    }
      //比较复杂的一种遍历在这里,呵呵~~他很暴力哦,它的灵活性太强了,想得到什么就能得到什么~~
    public static void workByEntry(Map<String, Student> map) {
    Set<Map.Entry<String, Student>> set = map.entrySet();
    for (Iterator<Map.Entry<String, Student>> it = set.iterator(); it.hasNext();) {
    Map.Entry<String, Student> entry = (Map.Entry<String, Student>) it.next();
    System.out.println(entry.getKey() + "--->" + entry.getValue());
    }
    }
  • 相关阅读:
    MYSQL: MYSQLBINLOG命令查看日志文件
    JAVA MAIL 发送邮件(SSL加密方式,TSL加密方式)
    Spring和Email整合详解
    java 版百度网盘功能
    Spring @Conditional注解 详细讲解及示例
    spring注解之@Import注解的三种使用方式(转载)
    Redis protected-mode属性解读
    5
    4
    3
  • 原文地址:https://www.cnblogs.com/chen-dch/p/4012598.html
Copyright © 2011-2022 走看看