Map的3种遍历[轉]
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种遍历[轉]的更多相关文章
- Java中Map的三种遍历方法
Map的三种遍历方法: 1. 使用keySet遍历,while循环: 2. 使用entrySet遍历,while循环: 3. 使用for循环遍历. 告诉您们一个小秘密: (下↓面是测试代码,最爱看 ...
- Map的三种遍历
import java.util.*;/*** Map的三种遍历方式* @author Administrator**/public class m {public static void main( ...
- Map的四种遍历
//Map的四种遍历方法 public static void main(String[] args) { Map<String, String> map = new HashMap< ...
- Map 的四种遍历方式
Map 的四种遍历方式 import java.util.HashMap; import java.util.Iterator; import java.util.Map; public class ...
- map的三种遍历方法!
map的三种遍历方法! 集合的一个很重要的操作---遍历,学习了三种遍历方法,三种方法各有优缺点~~ /* * To change this template, choose Tools | Te ...
- map的4种遍历方式
System.out.println("key= "+ key + " and value= " + map.get(key)); } ...
- java map的四种遍历
四种遍历: public static void main(String[] args) { Map<String, String> map = new HashMap<String ...
- Map的三种遍历方式
对于Map的三种方式遍历 1.keySet() 2.values() 3.entrySet()三种方式得到Set之后,都可以使用 foreach或者iterator, 不能使用for,因为数据结构决定 ...
- Map的两种遍历方式
********************************************************************************* ****************** ...
随机推荐
- GDB调试器
/*this project used for gdb debug c programs*//*At first,using compile command turn out the executab ...
- java 计算器基于工厂模式和功能单一模式
import java.util.Scanner; public class CaculationTest { public static void main(String[] args) { Sca ...
- 【转】 iOS日常学习 - iOS10上关于NSPhotoLibraryUsageDescription等问题
原文网址:http://blog.csdn.net/wang631106979/article/details/52578001 最近升级了Xcode8.0,真是很多坑啊,填完一个来另外一个,今天又遇 ...
- unity,生成的mac版游戏切场景时卡死解法
unity版本为5.1.1,在编辑器里运行没问题,build出的windows版运行也没问题,但build出的mac版在个别场景切换时会卡死,通过查看log(查看build版本log的方法参考:htt ...
- 解决 nginx https反向代理http协议 302重定向localtion到http问题
location /rest { #proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remot ...
- C#接口作用的深入理解
1.C#接口的作用 C#接口是一个让很多初学C#者容易迷糊的东西,用起来好像很简单,定义接口,里面包含方法,但没有方法具体实现的代码,然后在继承该接口的类里面要实现接口的所有方法的代码,但没有真正认识 ...
- MySQLAdmin用法
MySQLAdmin用法用于执行管理性操作.语法是:shell> mysqladmin [OPTIONS] command [command-option] command ...通过执行mys ...
- 提示“应用程序无法启动,因为应用程序的并行配置不正确”不能加载 System.Data.SQLite.dll
新版本SQLITE,如果下载Precompiled Binaries版会出现提示“应用程序无法启动,因为应用程序的并行配置不正确”不能加载 System.Data.SQLite.dll. 下载Prec ...
- vue通过判断写样式(v-bind)
v-bind:style="$index % 2 > 0?'background-color:#FFF;':'background-color:#D4EAFA;'"
- 装过photoshop后出现configuration error
1.你用的应该是精简版的PS,找到ps启动图标,点击右键,以管理员身份运行试试. 2.可以右键你的快捷方式,选择兼容性,后面有个选框“以管理员身份运行”,应用,下次就不报错了.