Map的使用与遍历
来源:互联网 发布:人上人 知乎 编辑:程序博客网 时间:2024/06/04 23:27
转自:http://dict.xsoftlab.net/dict/the-use-of-map-and-java-traversal ,谢谢
Map的使用与遍历
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
37
38
package
net.xsoftlab.dict;
import
java.util.HashMap;
import
java.util.Iterator;
import
java.util.Map;
import
java.util.Set;
public
class
TextMap {
public
static
void
main(String[] args) {
// 创建Map
Map<String, String> map =
new
HashMap<String, String>();
// 插入元素
map.put(
"key1"
,
"value1"
);
map.put(
"key2"
,
"value2"
);
// 移除元素
map.remove(
"key1"
);
// 清空map
map.clear();
map.put(
"key3"
,
"value3"
);
map.put(
"key4"
,
"value4"
);
// 遍历map 方法1
Set<String> set = map.keySet();
Iterator<String> iterator = set.iterator();
while
(iterator.hasNext()) {
String str = iterator.next();
System.out.println(str +
"/"
+ map.get(str));
}
// 遍历map 方法2
for
(Map.Entry<String, String> entry : map.entrySet()) {
System.out.println(entry.getKey() +
"--->"
+ entry.getValue());
}
}
}
0 0
- Map的使用与遍历
- ava map的使用与遍历
- java map的使用与遍历
- STL map的遍历与pair的使用
- map的遍历与删除
- Map的比较与遍历
- Map的遍历:keySet与entrySet
- java与freemarker中map的遍历
- Qt QMap与std map的遍历
- java与freemarker中map的遍历
- freemaker中list与map的遍历
- js map()与forEach()遍历的区别
- Java 中Map的使用,以及遍历
- shell中map的使用和遍历
- Java中map的使用和遍历
- Map的遍历,使用内部接口Entry
- Linux_Shell_ Map 的使用和遍历
- ReactJS 中数组遍历 map的使用
- depmod: ERROR: could not open directory /lib/modules/ 解决方法
- Google输了官司,物联网恐怕也不能用Java了吧
- java框架是什么意思?
- Scala 特质
- 大数据的最大价值: 大数据+物体=智能
- Map的使用与遍历
- 程序员们都是不被世人所理解的真正天才吗?-请大家看这个数独的解法
- 前端test
- undefined reference to 'pthread_create'问题解决
- 一致性哈希和负载均衡
- android 实用代码
- 本地搭建nuget服务器
- 一些关于socket的好的文章记载
- Spring IOC-XmlBeanFactory如何加载xml及如何存储转换后的信息