1、双列集合一次需要存一对数据,分别为键和值。
2、键不可以重复,值可以重复。
3、键和值是一一对应的,每一个键只能找到自己对应的值。
4、键+值这个整体,我们将其称之为“键值对”,或者“键值对对象”,在Java中叫做“Entry”对象。
Map是双列集合的顶层接口,他所有的功能都能被其他双列集合使用。
public static void main(String[] args) {
//1、创建Map的对象
Map<String,String> map=new HashMap<>();
//2、添加元素
//put方法的细节
//添加/覆盖
//在添加数据的时候,如果键不存在,那么直接把键值对对象存入map集合中。
//在添加数据的时候,如果键存在,会把原来的键值覆盖,并返回被覆盖的值。
map.put("zhangsan","zhang");
map.put("zhangsan","zhang2");
//3、删除
map.remove("zhangsan");
//4、清空
map.clear();
//5、判断是否包含
boolean Result =map.containsKey("zhangsan");
System.out.println(Result);
boolean Result1=map.containsValue("zhang");
System.out.println(Result1);
boolean Result2=map.isEmpty();
System.out.println(Result2);
//判断长度
int size=map.size();
System.out.println(size);
//打印集合
System.out.println(map);
}