代码示例:
package com.jredu.oopch08;
/**
* 主题
* @author Administrator
*
*/
public class Theme {
private int id;
private String title;
private String remark;
public Theme(int id, String title, String remark) {
super();
this.id = id;
this.title = title;
this.remark = remark;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
}
package com.jredu.oopch08;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class Ch01 {
public static void main(String[] args) {
//存储数据的地址
Set set = new HashSet<>();
//存储数据
set.add(new Theme(1,"标题1","简介1"));
set.add(new Theme(2,"标题2","简介1"));
//遍历数据
Iterator iter = set.iterator();
while(iter.hasNext()){
Theme theme = (Theme)iter.next();
System.out.println(theme.getId()+theme.getTitle()+theme.getRemark());
}
}
}