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
}
}
*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
}
}
相关文章推荐
- map映照容器(常用的使用方法总结)
- 第十章 Scala 容器(四):使用Map方法解决问题
- [转载]C++中 使用数组作为map容器VAlue值的解决方法
- 【STL容器学习】-关联容器与map的使用方法
- STL 之 C++ Map容器的简单使用方法
- C++中 使用数组作为map容器VAlue值的解决方法
- 【C++】map容器的使用方法
- Java学习之容器上(Collection接口常用方法,Iterator接口,使用foreach循环遍历Collection集合元素,Set集合通用知识(Hashset类,hashcode()与Lin
- Java学习之容器上(Collection接口常用方法,Iterator接口,使用foreach循环遍历Collection集合元素,Set集合通用知识(Hashset类,hashcode()与LinkedHashSet类))
- 一滴水:关于Java容器类库概念及Map.put();方法的使用
- C++ STL容器的使用方法(vector、queue、list、set、map)
- vector,map各种容器类型的使用方法总结
- map容器的简单概述及入门的定义和使用方法
- C++中 使用数组作为map容器VAlue值的解决方法
- Map容器——HashMap及常用API,及put,get方法解析,哈希码的产生和使用
- mapview使用方法
- 在程序中map的简单使用方法——续
- java.util.List接口的方法subList()的使用注意事项
- 转:php park、unpark、ord 函数使用方法(二进制流接口应用实例)
- 如何编码之使用接口作为方法的参数类型