zoukankan      html  css  js  c++  java
  • java の map集合遍历

    遍历map集合

    1. map的keySet()方法返回集合中所有键对象的集合。
    2. mapentrySet()方法一个存放了Map.Entry类型的set集合,每个Map.Entry对象代表map中的一对键与值。、
     //Map遍历
        public static void main(String[] args)
        {
            Map<String,String> map = new HashMap<String,String>();
            map.put("a", "monday");
            map.put("b", "wednesday");
            map.put("c", "thursday");
            map.put("d", "tuesday");
            //方法1
            Set<String> set = map.keySet();
            Iterator<String> it = set.iterator();
            while(it.hasNext()){
                String key = it.next();
                String value = map.get(key);
                System.out.println(value);
            }
            //方法2
            Iterator<Map.Entry<String,String>> its = map.entrySet().iterator();
            while(its.hasNext()){
                Map.Entry<String,String> m= its.next();
                System.out.println(m.getKey()+":::"+m.getValue());
            }
        }

     java主要集合的框架图

    Collection接口的方法

    Iterator接口隐藏底层集合的数据结构,向客户程序提供了遍历各种类型的集合的统一接口。Iterator接口中声明了如下方法:

    *   hasNext() : 判断集合中的元素是否遍历完毕,如果没有,就返回true.

    * next() : 返回下一个元素。

    * remove() : 从集合中删除上一个由next()方法返回的元素。

  • 相关阅读:
    html之marquee详解
    委托delegate
    sql server 循环
    数据库可疑
    WP8数据存储--独立存储文件
    WP8数据存储--独立存储设置
    jQuery Mobile 自定义导航条图标
    JQuery Mobile 图片布局
    自定义jQuery Mobile工具栏按钮
    css透明度的设置 (兼容所有浏览器)
  • 原文地址:https://www.cnblogs.com/zyoohoo/p/2540464.html
Copyright © 2011-2022 走看看