1.利用map的key唯一
// Map<String,Object>map=new HashMap<>();
// for (MobileCollectQuestionSubject subject:list) {
// map.put(subject.getSubjectId(),subject);
// }
// list.clear();
// for (String key:map.keySet()) {
// list.add((MobileCollectQuestionSubject) map.get(key));
// }
2 去重使用java8
Set<MobileCollectQuestionSubject> m=list.stream().collect(Collectors.toSet());
list=m.stream().collect(Collectors.toList());
3 java 8
examRoundDto.getExamObjects().stream().filter(examObjectDto -> examObjectDto.getType().equals(String.valueOf(ExaminationObjectType.EXAMINATION_PAPER_TYPE.getValue())))
.forEach(examObjectDto -> {
myExamPaperInfo.setPaperTypes(Integer.valueOf(examObjectDto.getObjectId()));
});
4 java8 根据数组列表的内置对象的元素进行排序
advertisementInfos list
//排序,让首页按照顺序显示
Collections.sort(advertisementInfos, new Comparator<AdvertisementInfo>(){
public int compare(AdvertisementInfo o1, AdvertisementInfo o2) {
if(o1.getAdSortNumber() > o2.getAdSortNumber()){
return 1;
}
if(o1.getAdSortNumber() == o2.getAdSortNumber()){
return 0;
}
return -1;
}
});
网友评论