java 去重的list_java --List<Object>去重

1.从数据库获取到的数据(没有办法一次性取回数据)

//搜索商店

List searchShopVO = shopInfoMapper.searchShop(searchContent, type,locationId,orderType,pageNums,lastTime);

//搜索服务

List searchServiceVO = shopInfoMapper.searchService(searchContent, type, locationId, orderType, pageNums, lastTime);

//SearchShopVO类如下

public class SearchShopVO {

private Integer shopId;

private String shopLogoUrl;

private String shopName;

private List shopServiceType;

private String totalScore;

private String address;

private String longitude;

private String latitude;

private String updTime;

private List shopService;

//get set方法省略

……

}

工程需求: 1.合并searchShopVO与searchServiceVO,组成searchShopVO 2.searchShopVO去重,条件是shopId 3.返回searchShopVO即可 数据库请求回来的数据 searchShopVO={ 1000000003 1000000009 1000000008 1000000007 1000000006 1000000005 1000000004 1000000002 1000000001 1000000000 } searchServiceVO={ 1000000003 1000000004 1000000002 1000000001 1000000000

} 很明显,重复了5条记录(03,04,02,01,00) 下面是去重方法

//1.合并到一个list中

searchShopVO.addAll(searchServiceVO);

//2.取出所有的shopId

List resultListInteger = new ArrayList();

List resultListSearchShopVO = new ArrayList();

for (int i = 0; i < searchShopVO.size(); i++) {

resultListInteger.add(searchShopVO.get(i).getShopId());

}

//3.shopId去重

List tempList= new ArrayList();

for (int i = 0; i < resultListInteger.size(); i++) {

if (!tempList.contains(resultListInteger.get(i))) {

tempList.add(resultListInteger.get(i));

resultListSearchShopVO.add(searchShopVO.get(i));

}

}

最后返回的结果是resultListSearchShopVO

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值