Map<String, String> map = new HashMap<String, String>();
map.put("A", "AAA");
map.put("B", "BBB");
map.put("C", "CCC");
map.put("D", "DDD");

// 第一种用for循环

for (Map.Entry<String, String> entry : map.entrySet()) {
System.out.println(entry.getKey() + "--->" + entry.getValue());
}

// 第二种用迭代

Set set = map.entrySet();
Iterator it = set.iterator();
while (it.hasNext()) {
Map.Entry<String, String> entry1 = (Map.Entry<String, String>) it.next();
System.out.println(entry1.getKey() + "==" + entry1.getValue());
}

Iterator it = map.keySet().iterator();
while (it.hasNext()) {
String key;
String value;
key = it.next().toString();
value = map.get(key);
System.out.println(key + "--" + value);
}

// 用entrySet()迭代

Iterator<Entry<String, String>> it = map.entrySet().iterator();
System.out.println(map.entrySet().size());
String key;
String value;
while (it.hasNext()) {
Map.Entry entry = it.next();
key = entry.getKey().toString();
value = entry.getValue().toString();
System.out.println(key + "====" + value);
}

Map的3种遍历[轉]的更多相关文章

  1. Java中Map的三种遍历方法

    Map的三种遍历方法: 1. 使用keySet遍历,while循环: 2. 使用entrySet遍历,while循环: 3. 使用for循环遍历.   告诉您们一个小秘密: (下↓面是测试代码,最爱看 ...

  2. Map的三种遍历

    import java.util.*;/*** Map的三种遍历方式* @author Administrator**/public class m {public static void main( ...

  3. Map的四种遍历

    //Map的四种遍历方法 public static void main(String[] args) { Map<String, String> map = new HashMap< ...

  4. Map 的四种遍历方式

    Map 的四种遍历方式 import java.util.HashMap; import java.util.Iterator; import java.util.Map; public class ...

  5. map的三种遍历方法!

    map的三种遍历方法!   集合的一个很重要的操作---遍历,学习了三种遍历方法,三种方法各有优缺点~~ /* * To change this template, choose Tools | Te ...

  6. map的4种遍历方式

            System.out.println("key= "+ key + " and value= " + map.get(key));    }   ...

  7. java map的四种遍历

    四种遍历: public static void main(String[] args) { Map<String, String> map = new HashMap<String ...

  8. Map的三种遍历方式

    对于Map的三种方式遍历 1.keySet() 2.values() 3.entrySet()三种方式得到Set之后,都可以使用 foreach或者iterator, 不能使用for,因为数据结构决定 ...

  9. Map的两种遍历方式

    ********************************************************************************* ****************** ...

随机推荐

  1. 配置Apache将自己的电脑做服务器使局域网内的电脑访问自己的主机

    很多的朋友都想把自己的电脑打造为服务器使别人能够访问.比如说你自己写了一网站,只能自己通过localhost访问或127.0.0.1访问.但是怎么让别人的电脑也能访问呢?来看看自己写的网站.现在我来讲 ...

  2. 多网卡 指定网卡到指定IP

    route add -net 1.2.3.0/24 gw 网关 route add -host 目标IP dev eth1route add -host 目标IP gw 网关

  3. __LINE__ __DATE__ __FILE__ __TIME__ 等宏定义解释

    Names the predefined ANSI C and Microsoft C++ implementation macros. The compiler recognizes predefi ...

  4. 了解oracle数据库的情况

    1.了解你的数据库版本号 2.是否配置了DataGuard? SQL> select protection_mode, protection_level, remote_archive,data ...

  5. 用margin还是用padding

    用margin还是用padding这个问题是每个学习CSS进阶时的必经之路. 分类: Html/CSS | 转载请注明: 出自 海玉的博客 本文地址: http://www.hicss.net/use ...

  6. RESTful架构

    RESTful架构 1.什么是RESTful API设计原则 REST是Representational State Transfer的简写,意为“表现层状态转换” 是一种对资源状态进行操作的设计规则 ...

  7. ruby-thread/process

    thread a = 1 threads = [] mutex = Mutex.new 5.times do threads << Thread.new do 1000.times do ...

  8. RequireJS 文件合并压缩

    RequireJS的define 以及require 对于我们进行简化JavaScript 开发,进行模块化的处理具有很大的帮助 但是请求加载的js 文件会有一些影响,一般的处理是对于文件进行压缩,但 ...

  9. SQL集合运算参考及案例(一):列值分组累计求和

    概述 目前企业应用系统使用的大多数据库都是关系型数据库,关系数据库依赖的理论就是针对集合运算的关系代数.关系代数是一种抽象的查询语言,是关系数据操纵语言的一种传统表达方式.不过我们在工作中发现,很多人 ...

  10. You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法

    报错如下:java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test2/com.exampl ...