@RunWith(SpringRunner.class)
@SpringBootTest
public class test {
Map<String,Integer> map;
@Test
public void test(){
//通过put方法添加(修改)键值对,第一个参数是键,第二个参数是值。
//通过get方法查询元素,参数就是键名
this.map = new HashMap<String, Integer>();
map.put("id",1);
System.out.println("~~~~~ "+map.get("id"));
//通过keySet()方法获取一个所有键名组成的Set集合
map.put("age",20);
Set<String> s = map.keySet();
for (String ss : s){
System.out.println("!!!!!!!!!!! "+ ss);
}
//删除
map.remove("id");
Set<Map.Entry<String,Integer>> set = map.entrySet();
for (Map.Entry mm : set){
System.out.println("@@@@@@@@@@@@ "+ mm);
System.out.println("############## "+mm.getKey()); //age
System.out.println("$$$$$$$$$$$$ "+mm.getValue()); //20
}
}
}
Map的增删改
最新推荐文章于 2023-08-03 20:00:00 发布