Commit bb0a122d by 景园园

HashMap测试类

parent e0bcec3d
package cn.freemud.demo;
import org.junit.Test;
import java.util.HashMap;
/**
*测试HashMap
* @author jingyuanyuan
*/
public class HashMapTest {
/**
* HashMap的键和值都可以存储为null
*/
@Test
public void test(){
System.out.println("hello this is test");
HashMap map=new HashMap();
map.put(null,"你好");
map.put("key1",null);
System.out.println("map size:"+map.size());
System.out.println("key is null value:"+map.get(null));
System.out.println("value is null value:"+map.get("key1"));
}
/**
* clear 清空集合
*/
@Test
public void clearTest(){
HashMap map=new HashMap();
map.put("key1","张三");
System.out.println("map size:"+map.size());
map.clear();
System.out.println("map size:"+map.size());
}
/**
* clone 克隆集合
*/
@Test
public void cloneTest(){
HashMap map=new HashMap();
map.put("key1","张三");
map.put("key2","李四");
System.out.println("map size:"+map.size());
Object clone = map.clone();
System.out.println("clone map size:"+clone);
}
/**
* 测试集合中是否包含指定的key
*/
@Test
public void containsKeyTest(){
HashMap map=new HashMap();
map.put("key1","张三");
map.put("key2","李四");
boolean key1 = map.containsKey("key1");
boolean key3 = map.containsKey("key3");
System.out.println("containsKey key1:"+key1);
System.out.println("containsKey key3:"+key3);
}
/**
* 测试集合中是否包含指定的value
*/
@Test
public void containsValueTest(){
HashMap map=new HashMap();
map.put("key1","张三");
map.put("key2","李四");
boolean a = map.containsValue("张");
boolean b = map.containsValue("李四");
System.out.println("containsValue 张:"+a);
System.out.println("containsValue 李四:"+b);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment