已经给楼主写了个例子..
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
public class HashMapTest {
public static void main(String[] args){
HashMap<String,Object> hm=new HashMap<String,Object>();
People p1=new People();
People p2=new People();
People p3=new People();
People p4=new People();
hm.put("People3", p1);
hm.put("People1", p2);
hm.put("People4", p3);
hm.put("People2", p4);
Iterator<String> it=hm.keySet().iterator();
while(it.hasNext()){
System.out.println(it.next());
}
}
}
class People {
private String name;
private int age;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
运行了没问题..
祝楼主早日成功!
温馨提示:答案为网友推荐,仅供参考