Map集合的遍历[通俗易懂]
2023-06-13 09:11:24 时间
大家好,又见面了,我是你们的朋友全栈君。
COPY/** * Map接口的使用 * 特点:1.存储键值对 2.键不能重复,值可以重复 3.无序 */
public class Demo1 {
public static void main(String[] args) {
Map<String,Integer> map=new HashMap<String, Integer>();
//1.添加元素
map.put("tang", 21);
map.put("he", 22);
map.put("fan", 23);
System.out.println(map.toString());
//2.删除元素
map.remove("he");
System.out.println(map.toString());
//3.遍历
//3.1 使用keySet();
for (String key : map.keySet()) {
System.out.println(key+" "+map.get(key));
}
//3.2 使用entrySet();效率较高
for (Map.Entry<String, Integer> entry : map.entrySet()) {
System.out.println(entry.getKey()+" "+entry.getValue());
}
}
}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/139203.html原文链接:https://javaforall.cn
相关文章
- java map 二维数组_Java二维数组实现简单Map
- Java Map集合的详解「建议收藏」
- 遍历ArrayList、遍历Map
- java中hashmap遍历_map遍历的两种方式
- 有序的Map集合_map集合特点
- 在 JavaScript 中,什么时候使用 Map 或胜过 Object
- java map是有序的吗_java中map遍历
- 数组方法底层实现:push pop map遍历 个人理解实现方法
- Java8中Map的遍历方式总结
- 【Groovy】map 集合 ( map 集合遍历 | 使用 map 集合的 find 方法遍历 map 集合 | 代码示例 )
- Java8中Map的遍历方式总结详解编程语言
- struts2:OGNL表达式,遍历List、Map集合;投影的使用详解编程语言
- JAVA基础之Map接口详解编程语言
- Redis有序Map:高效有序排列的利器(redis有序map)
- 集Oracle中存储Map集的新方法(oracle保存map)
- 使用Redis存储Map结构数据(将map存到redis中)
- Oracle Map映射从实施到实现(oracle map映射)
- Redis脚本快速遍历Map集(redis脚本遍历map)
- js遍历json返回的map内容示例代码