码迷,mamicode.com
首页 > 其他好文 > 详细

Map 基础用法

时间:2017-04-26 13:11:19      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:val   clear   util   value   void   oid   ati   rem   equals   

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Test {

	public static void main(String[] args) {
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("hah", 123);
		map.put("aa", 12314);
		map.put("xu", "123");
//		map.clear();
		Object object = map.get("hah");
		System.out.println("map.get:" + object);
		
		boolean containsKey = map.containsKey("hah");
		System.out.println("map.containsKey:" + containsKey);
		
		int hashCode = map.hashCode();
		System.out.println("map.hashCode:" + hashCode);
		
		boolean empty = map.isEmpty();
		System.out.println("map.isEmpty:" + empty);
		
		Set<String> keySet = map.keySet();
		System.out.println("map.keySet:" + keySet);

		Object remove = map.remove("xu");
		System.out.println("map.keySet:" + map.keySet());
		
		int size = map.size();
		System.out.println("map.size:" + size);
		
		Collection<Object> values = map.values();
		System.out.println("map.values:" + values);
		
		Set<String> keySet2 = map.keySet();
		System.out.println("map.keySet2:" + keySet2);
		
		Map<String, Object> map1 = new HashMap<String, Object>();
		map1.put("aa", "123");
		map1.put("bb", 234);
		
		Map<String, Object> map2 = new HashMap<String, Object>();
		map2.put("aa", "123");
		map2.put("bb", 234);
		boolean equals2 = map1.equals(map2);
		System.out.println("map2.equals:" + equals2);
	}
}

  

map.get:123
map.containsKey:true
map.hashCode:163837
map.isEmpty:false
map.keySet:[aa, hah, xu]
map.keySet:[aa, hah]
map.size:2
map.values:[12314, 123]
map.keySet2:[aa, hah]
map2.equals:true

  

Map 基础用法

标签:val   clear   util   value   void   oid   ati   rem   equals   

原文地址:http://www.cnblogs.com/xu-dong/p/6767829.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!