Aumentar: put ()
Excluir: remover ()
Verificar: get ()
Inserir: put ()
Traversal: Percurso do iterador
/*
一:Map接口当中常用的方法(抽象方法)
*/
public class MapMethod {
@Test
public void test(){
//1.添加数据 put
Map map=new HashMap();
map.put("AA",123);
map.put(45,123);
map.put("BB",56);
map.put("AA",87);
System.out.println(map);//{AA=87, BB=56, 45=123} 体现了替换
//2.添加整个map的数据放入新的map putAll()
Map map1=new HashMap();
map1.putAll(map);
System.out.println(map1);
//3.remove(Object key)移除某个键值对
Object aa = map.remove("AA");
System.out.println(aa);//87
System.out.println(map);//{BB=56, 45=123}
//4.clear()
map.clear();//只是清空数据
System.out.println(map.size());//0 不是null值
}
@Test
public void test2(){
Map map=new HashMap();
map.put("AA",123);
map.put(45,123);
map.put("BB",56);
map.put("AA",87);
//5.获取指定Key值对应的value get(Object key)
System.out.println(map.get(45));
//6.ContainsKey(Object key) 判断是否包含指定key值
boolean aa = map.containsKey("AA");
System.out.println(aa);//true
//7.ContainsValues (Object values) 判断是否包含指定Values
boolean b = map.containsValue(123);
System.out.println(b);//true
//8.int size() 返回map中key-values 的个数
int size = map.size();
System.out.println(size);//3
//9.boolean is Empty() 判断当前map是否为空
boolean empty = map.isEmpty();
System.out.println(empty);//false
//10. boolean equals(Object obj): 判断当前map和参数对象obj是否相等
}