`
javacto
  • 浏览: 81938 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

TestMap 【007】

map 
阅读更多
package com.testmap;
import java.util.* ;
public class TestMap {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Map map1 = new HashMap() ;
		Map map2 = new  TreeMap() ;
		Map map3 = new TreeMap() ;
		map1.put("one", new Integer(1)) ;
        // map1.put("one", 1) ; //autoBoxing   自动打包从1.5 后自动打包和解包
		map1.put("two", new Integer(2)) ;
		map1.put("three",new Integer(3)) ;
		map2.put("four","good") ;
		map2.put("five", "study") ;
		

		System.out.println(map1) ;
		System.out.println(map1.size()) ;
		System.out.println(map1.keySet()) ;
		System.out.println(map1.values()) ;
		System.out.println(map1.entrySet()) ;
		System.out.println(map1.equals(map2)) ;
		System.out.println(map1.get("thr")) ; //返回指定键所映射的值;如果此映射不包含该键的映射关系,则返回 null。
		System.out.println(map1.hashCode()) ;
		System.out.println(map1.isEmpty()) ;
		System.out.println(map3.isEmpty()) ;
		
		System.out.println(map1.containsKey("two")) ;// 判断是否包含该键
		System.out.println(map1.containsValue(4)) ; //判断是否包含指定的值
		if(map1.containsKey("two")) {
			int i = ((Integer) map1.get("two")).intValue() ;
			System.out.println(i) ;
		}
		
		System.out.println(map2) ;
		map3.putAll(map1) ; //从指定映射中将所有映射关系复制到此映射中
		System.out.println(map3) ;
		map3.remove("one") ; // 移除键值 one
		System.out.println(map3) ;
		

	}

}


console :

{two=2, one=1, three=3}
3
[two, one, three]
[2, 1, 3]
[two=2, one=1, three=3]
false
null
110564946
false
true
true
false
2
{five=study, four=good}
{one=1, three=3, two=2}
{three=3, two=2}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics