hashmap基础使用方法

hashmap基础使用方法

1.创建hashmap

Map<Integer,Integer> map=new HashMap<>();
Map<String,String> map=new HashMap<>();

2.put.方式添加数据,key-value

map.put(2,3);
//Map<String,String>,加引号
map.put("2","3");
/

/键值不会重复,会覆盖掉
map.put(2,4);
3.putall

map1.putall(map2);

4.remove()

//键值,没有的话不报错
map.remove(1);

5.entrySet()遍历

for(Map .Entry<String,String> entry : map.entrySet()){
	System.out.println(entry.getKey()+"="+entry.getValue());
}
6

.get()

//通过键值取value
map.get(1);

猜你喜欢

转载自blog.csdn.net/code_mzh/article/details/105768648
今日推荐