其他分享
首页 > 其他分享> > List去重

List去重

作者:互联网

写在前面

需求:

需要将totalList中的某些重复记录移除.思路是把需要移除的记录存入removeList,  然后遍历移除.

代码

            // 去除重复ref_no的记录 start==
            if (resultList != null && !resultList.isEmpty()) {
                List<String> needRemoveRefNoList = new ArrayList<>();
                for (CaTopupRec caTopupRec : resultList) {
                    if (caTopupRec.getTopupAmt().compareTo(BigDecimal.ZERO) < 0) {
                        needRemoveRefNoList.add(caTopupRec.getRefNo());
                    }
                }
                if (!needRemoveRefNoList.isEmpty()) {
                    for (Iterator<CaTopupRec> iterator = resultList.iterator(); iterator.hasNext(); ) {
                        CaTopupRec next = iterator.next();
                        if (needRemoveRefNoList.contains(next.getRefNo())) {
                            iterator.remove();
                        }
                    }
                }

 

标签:caTopupRec,iterator,List,resultList,next,移除,needRemoveRefNoList
来源: https://www.cnblogs.com/yadongliang/p/11542815.html