#for循环包裹多重if语句,数据被覆盖的问题
有个List<字符串> 的集合 使用for循环 if判断对应的值会导致后一条数据覆盖前一条数据的值
for (String s : list) {
if ("0".equals(s)){
reprotTem.setNewApplication(textRenderData);
}else if ("0"){
reprotTem.setNewApplication(unCancel);
}
//如果是监督
if ("1".equals(s)){
reprotTem.setSupervision(textRenderData);
}else{
reprotTem.setSupervision(unCancel);
}
}
###解决方法:使用set
HashSet<String> hs = new HashSet<>();
hs.addAll(list);
if (hs.contains("0")){
reprotTem.setNewApplication(textRenderData);
}else {
reprotTem.setNewApplication(unCancel);
}
if (hs.contains("1")) {
reprotTem.setSupervision(textRenderData);
}else {
reprotTem.setSupervision(unCancel);
}