阅读背景:

Map中的HashMap存储对象

来源:互联网 
<pre name="code" class="java">package test;

import java.util.HashMap;
import java.util.Iterator;

public class hashmapdemo {
	public static void main(String[] args){
		HashMap<Student,String> hm = new HashMap<Student,String>();
		
		hm.put(new Student("wangwu",23),"shanghai");
		hm.put(new Student("wangwenwen",28),"北京");
		hm.put(new Student("zhangming",20),"武汉");
		hm.put(new Student("xiaoqiang",35),"天津");
		
		Iterator<Student> it = hm.keySet().iterator();
		
		while(it.hasNext()){
			Student key = it.next();
			
			String value = hm.get(key);
			
			System.out.println(key.name+":"+key.age+"----"+value);
		}
	}
	
}<pre name="code" class="java">package test;

im



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: