下面是我做的一个简单列子:供大家参考!
1.定义实体类: Content
public class Content {
private String name;
private long time;
public Content(String name, long time){
this.name=name;
this.time=time;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public long getTime() {
return time;
}
public void setTime(Long time) {
this.time = time;
}
}
2.下面是测试类: Test
public class Test {
public static void main(String[] args) {
//声明map 对象
Map<Content, String[]> m =new IdentityHashMap<Content, String[]>();
//给map 对象赋值
m.put(new Content("wang",123456l), new String[]{"111"});
m.put(new Content("wang1",123457l), new String[]{"222","3333"});
Set<Map.Entry<Content, String[]>> set = set = m.entrySet();
//得到集合
Iterator<Map.Entry<Content, String[]>> iter = set.iterator();
//循环遍历
while (iter.hasNext()) {
Map.Entry<Content, String[]> me =iter.next();
System.out.println("======="+me.getKey().getName()+"======"+me.getValue()[0]);
}
}
}
3.输出结果:
wang1===222===3333
wang===111===
1.定义实体类: Content
public class Content {
private String name;
private long time;
public Content(String name, long time){
this.name=name;
this.time=time;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public long getTime() {
return time;
}
public void setTime(Long time) {
this.time = time;
}
}
2.下面是测试类: Test
public class Test {
public static void main(String[] args) {
//声明map 对象
Map<Content, String[]> m =new IdentityHashMap<Content, String[]>();
//给map 对象赋值
m.put(new Content("wang",123456l), new String[]{"111"});
m.put(new Content("wang1",123457l), new String[]{"222","3333"});
Set<Map.Entry<Content, String[]>> set = set = m.entrySet();
//得到集合
Iterator<Map.Entry<Content, String[]>> iter = set.iterator();
//循环遍历
while (iter.hasNext()) {
Map.Entry<Content, String[]> me =iter.next();
System.out.println("======="+me.getKey().getName()+"======"+me.getValue()[0]);
}
}
}
3.输出结果:
wang1===222===3333
wang===111===