现在的位置: 首页 > 综合 > 正文

map的使用

2013年01月11日 ⁄ 综合 ⁄ 共 425字 ⁄ 字号 评论关闭
package 容器类;

import java.util.*;
// 所有的用法请参考  Api 文档
class Am{
	private int a;
	public Am(int a){
		this.a = a;
	}
	public int getA() {
		return a;
	}
}

public class map1 {
	public static void main(String[] args) {
		HashMap hm = new HashMap<Integer,Am>();
		hm.put(1,new Am(5)); //放入映射关系
		hm.put(2,new Am(5)); 
		Am am = (Am)hm.get(1); //提取映射关系
		System.out.println(am.getA());
		System.out.println(hm.containsKey(1)); 
		System.out.println(hm.size());
		hm.remove(1); // 删除映射关系
		System.out.println(hm.size());
	}
}

抱歉!评论已关闭.