class XS{
// 学号
String code;
private String getCode() {
return code;
}
}
class CJ{
XS xs;
//成绩
int score;
private XS getXs() {
return xs;
}
private void setXs(XS xs) {
this.xs = xs;
}
private int getScore() {
return score;
}
}
List buildCJList(List cjList,List xsList){
List needToAdd = new ArrayList();
// 如果找到就修改,没有找到,先记着,最后加,因为迭代器不允许中途add
for (XS xs : xsList) {
for (CJ cj : cjList) {
if (cj.getXs().getCode().equals(xs.getCode())) {
cj.setXs(xs);
}else {
needToAdd.add(xs);
}
}
}
for (XS xs : needToAdd) {
CJ cj = new CJ();
cj.setXs(xs);
cjList.add(cj);
}
return cjList;
}
刚才去忙别的事,晚了,看是不是你要的