最近开发程序碰到了一个有趣的问题,就是List<String>alllist或list<Integer>alllist去重复可以,
但是list 里如果是一个javabean就不行了,我在这里把代码贴出来跟大家分享一下。
List<Sample> listAll = new ArrayList<Sample>();
List<Integer>listsamp=new ArrayList<>();
for (Department department : departments) {
if (department == Department.ALL||department==Department.JC) {
continue;
}
List<Sample> listSample = sampleService.getReportRecieved(department,map);
for (int i = 0; i < listSample.size(); i++) {
if(!listsamp.contains(listSample.get(i).getSample_number())){
listsamp.add(listSample.get(i).getSample_number());
listAll.add(listSample.get(i));
}
}
// listAll.addAll(listSample);
}注:
List<Integer>listsamp用contains去重复可以,但是如果变成List<Sample> listAll用contians判断sample是否重复就不可以了。
本文出自 “大话程序” 博客,请务必保留此出处http://houqida.blog.51cto.com/8877896/1587431
原文地址:http://houqida.blog.51cto.com/8877896/1587431