Java Map遍历方式的选择
作者:网络转载 发布时间:[ 2013/4/11 10:09:30 ] 推荐标签:
entrySet遍历key+value(写法1):
Iterator<Entry<String, String>> iter = map.entrySet().iterator();
Entry<String, String> entry;
while (iter.hasNext()) {
entry = iter.next();
key = entry.getKey();
value = entry.getValue();
}
entrySet遍历key+value(写法2):
for (Entry<String, String> entry: map.entrySet()) {
key = entry.getKey();
value = entry.getValue();
}
2.2.2 遍历key
keySet遍历key(写法1):
Iterator<String> iter = map.keySet().iterator();
while (iter.hasNext()) {
key = iter.next();
}
keySet遍历key(写法2):
for (String key : map.keySet()) {
}
entrySet遍历key(写法1):
Iterator<Entry<String, String>> iter = map.entrySet().iterator();
while (iter.hasNext()) {
key = iter.next().getKey();
}
entrySet遍历key(写法2):
for (Entry<String, String> entry: map.entrySet()) {
key = entry.getKey();
}
2.2.3 遍历value
keySet遍历value(写法1):
Iterator<String> iter = map.keySet().iterator();
while (iter.hasNext()) {
value = map.get(iter.next());
}
keySet遍历value(写法2):
for (String key : map.keySet()) {
value = map.get(key);
}
entrySet遍历value(写法1):
Iterator<Entry<String, String>> iter = map.entrySet().iterator();
while (iter.hasNext()) {
value = iter.next().getValue();
}
entrySet遍历value(写法2):
for (Entry<String, String> entry: map.entrySet()) {
value = entry.getValue();
}
values遍历value(写法1):
Iterator<String> iter = map.values().iterator();
while (iter.hasNext()) {
value = iter.next();
}
values遍历value(写法2):
for (String value : map.values()) {
}
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11