import java.util.*;
public class map
{
public static void main( String[] args )
{
//Map list = new HashMap();
Map map = new HashMap<>();
map.put(1,"shen");
map.put(2,"wei");
System.out.println(map.size());
System.out.println("==================================1");
System.out.println(map);
System.out.println("==================================2");
System.out.println(map.get(1));
System.out.println(map.get(2));
System.out.println("==================================3");
Boolean a = map.containsKey(1); //此映射是否包含
System.out.println(a);
System.out.println("==================================4");
Boolean b = map.containsKey(3);
System.out.println(b);
System.out.println("==================================5");
map.remove(2);
System.out.println(map.size());
System.out.println(map);
System.out.println("==================================6");
Object value = map.get(1);
System.out.println(value);
System.out.println("==================================7");
Boolean c = map.containsValue("shen"); //是否包含指定值
System.out.println(c);
System.out.println("==================================8");
Boolean d = map.isEmpty(); //判断是否为空
System.out.println(d);
System.out.println("==================================9");
map.put(2,"wei");
map.put(3,"wei");
Set key = map.keySet(); //获取map中所有的key值,
System.out.println(key);
System.out.println("==================================9______1");
Collection value4 = map.values(); //获取map中所有的value值,
System.out.println(value4);
System.out.println("==================================9______2");
map.clear(); //清空
Boolean e = map.isEmpty();
System.out.println(e);
System.out.println("==================================10");
}
}
==============================================================================================================================================================
执行结果:
2
==================================1
{1=shen, 2=wei}
==================================2
shen
wei
==================================3
true
==================================4
false
==================================5
1
{1=shen}
==================================6
shen
==================================7
true
==================================8
false
==================================9
[1, 2, 3]
==================================9______1
[shen, wei, wei]
==================================9______2
true
==================================10