当前位置:千优问>常见问答>JAVA hashmap的用法

JAVA hashmap的用法

2023-01-22 11:03:55 编辑:join 浏览量:597

JAVA hashmap的用法

JAVA hashmap的用法

已经给楼主写了个例子..import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;public class HashMapTest { public static void main(String[] args){ HashMap hm=new HashMap(); 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 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; }}运行了没问题..祝楼主早日成功!

标签:JAVA,hashmap,用法