您的位置:首页 > 其它

Map 容器接口 及类中的方法的使用

2012-11-11 22:11 253 查看
/*

*Map 接口 及类中的方法的使用

*孔华生

*/

import java.util.*;

public class TestMap

{

public static void main(String[] args)

{

Map m1 = new HashMap();

Map m2 = new TreeMap();

m1.put("one",new Integer(1));

m1.put("two",new Integer(2));

m1.put("three",new Integer(3));

m2.put("A","kong");

m2.put("B","hua");

m2.put("C","sheng");

System.out.println(m2);//输出map内所有key 和value

System.out.println(m2.size());//输出m2内几个key-value对

m2.put("C","qiang");//将原value替代 ,会返回一个obj类型的对象,原value值。

System.out.println(m2);

//System.out.println( m2.lastKey());

//System.out.println( m2.firstKey());

System.out.println(m2.get("A"));

System.out.println(m1.containsKey("one"));//判断是否包含key one 若包含则 true

System.out.println(m1);//输出 m1的key-value

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: