您的位置:首页 > 其它

容器第五课,Map和HashMap的基本用法,hashMap和HashTable的区别

2015-03-10 17:09 369 查看
Map接口

实现Map接口的类用来存储键(Key) --- 值(value)对。

Map接口的实现类有HashMap和TreeMap类

Map类中存储的键---值对通过键来标识,所以键值不能重复

package com.pkushutong.Collection;

import java.util.HashMap;
import java.util.Map;

/**
* 测试Map的基本用法
* @author dell
*
*/
public class Test04 {
public static void main(String[] args) {
Map map = new HashMap();
map.put("张三", new wife("花花"));
map.put("李四", new wife("蕾蕾"));
//移除张三
map.remove("张三");
//是否存在李四键
boolean b = map.containsKey("李四");
wife w = (wife) map.get("张三");
System.out.println(w.name);
System.out.println(b);
}
}

class wife{
String name;
public wife(String name){
this.name = name;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐