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. 兼容FF 加入收藏夹和设为首页

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. PosPal银豹收银系统

    http://pospal.cn/pc.html 注册公司的地址,便宜的快法务 http://www.kuaifawu.com/

  3. unity3d中切换武器

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...

  4. 关于ftp操作内容记录

    ftp问题解决: http://www.linuxdiyf.com/viewarticle.php?id=272088 IPTABLES_MODULES="ip_nat_ftp ip_con ...

  5. Web前端开发笔试&面试_05

    >>CW 1.JavaScript的2种变量范围有什么不同? 2.JavaScript 的对象有哪些? 3.

  6. #linux包之sysstat之iostat命令

    概述 对于I/O-bond类型的进程,我们经常用iostat工具查看进程IO请求下发的数量.系统处理IO请求的耗时,进而分析进程与操作系统的交互过程中IO方面是否存在瓶颈.同vmstat一样,iost ...

  7. Windows Service Wrapper

    This project creates a wrapper executable that can be used to host any executable as an Windows serv ...

  8. vs2013创建mvc项目体系找不到指定文件

    在Visual Studio 2013中创建新MVC项目,(2013默认创建的就是mvc5的项目) 断定后提示,体系找不到指定的文件.(Exception HRESULT:08x0070002): 究 ...

  9. String 深浅拷贝的测试---有待继续测试

    public class TestString { void test1() { // TODO Auto-generated method stub String str = new String( ...

  10. Innodb 存储引擎(转)

    第一部分:线程 Innodb是一个多线程的,各个线程负责不同的任务.主要的线程有:Master Thread.IO Thread.Purge Thread.Page Cleaner Thread. 一 ...