问题:经过数据库查询得到的 List ,对里面的数据进行封装成对象保存到另一个List里面,因为对象是不同的,但是里面的内容有的是相同的,这时候要去掉重复的对象的方法是:
returnList = performanceDao.queryTToalinfoByEmpidService(uuMap);
List resultList = new ArrayList();//返回最终结果
List tempList = new ArrayList(); //过滤重复数据使用
if(returnList.size()>0){
for(int c=0;c<returnList.size();c++){
TTotalInfoName tTotalInfoName = new TTotalInfoName();
Object[] obj = (Object[])returnList.get(c);
TTotalinfo ttotalinfo = (TTotalinfo)obj[0];
TEmployee temployee = (TEmployee) obj[1];
//如果tempList集合中包含遍历到的对象的empid ,则resultList不添加这个对象
if(!tempList.contains(ttotalinfo.getEmpid())){
tempList.add(ttotalinfo.getEmpid());
tTotalInfoName.setEmpId(ttotalinfo.getEmpid());
tTotalInfoName.setEmpName(temployee.getLastname()+temployee.getFirstname());
resultList.add(tTotalInfoName);
}
}
}
思路:先取到遍历到的数据,判断数据是否在另一个List里面存在,存在的话则不在保存。