
map集合
weixin_43186788
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
map集合,输出全部的key,输出全部的value。
***输出全部的key public static void main(String[] args) { Map<String, String> map = new HashMap<>(); map.put(“key1”, “value1”); map.put(“key2”, “value2”); map.put(“key3”, “value3”); map.put(“key4”, “value4”); Set keys = map.keySet();// 得到全部的key Iter原创 2021-04-08 17:50:19 · 1097 阅读 · 0 评论 -
HashMap判断map集合中是否存在指定的key/value。
public static void main(String[] args) { // demo01(); Map<String, Integer> map = new HashMap<>(); map.put(“第一个”, 1); map.put(“第二个”, 2); map.put(“第三个”, 3); map.put(“第四个”, 4); if (map.containsKey(“第二个”)) {//判断map集合中是否存在指定的key System.out.println(“原创 2021-04-08 11:53:14 · 1544 阅读 · 0 评论 -
HashMap 向集合中增加或取出内容。
public static void main(String[] args) { Map<String, String> map = new HashMap<>(); map.put(“mldn”, “老王”);//增加内容 map.put(“zhinangtuan”, “隔壁的”); map.put(“mldjava”, “好的”); String string = map.get(“zhinangtuan”);//根据key取出value值 System.out.println(原创 2021-04-08 11:52:09 · 158 阅读 · 0 评论 -
Map集合迭代
通过查看Map集合的API发现没有iterator方法,那么双列集合如何迭代? 方法一:通过获取到所有键存储到set集合,然后根据迭代器得到map集合的所有值。 1.先通过keyset()方法获取到map集合中所有的key值 set keyset = map.keyset(); 2.获取迭代器遍历 Iterator it = keyset.iterator(); while(it.hasnext()){ 3.获取到每一个建 String key = it.next(); 4.根据键通过map.get()原创 2021-04-08 11:48:39 · 153 阅读 · 0 评论 -
map集合方法
map.put(key,value); //添加方法(第一次添加返回值为null、因为第一次添加的时候没有值,所以说返回的是被覆盖的值) map.remove(“key”); //根据键删除元素,返回对应的值 map.containskey(“key”); //判断是否包含传入的键 map.containsvalue(value); //判断是否包含传入的值 map.isempty(); //判断集合是否为空 Collectio原创 2021-04-08 11:20:07 · 90 阅读 · 0 评论