将两个List合并为一个List(并集)+取交集
2017-03-30 14:33
447 查看
并集
List<Integer> questionerIdList = new ArrayList<Integer>();List l1 = sysuserinfMapper.findSysuserIdsByrRealName(questionName);
List l2 = wechatinfMapper.selectWechatIdsByNickname(questionName);
questionerIdList.addAll(l1);
questionerIdList.addAll(l2);
//准备一个空的list,将两个list添加进去
StringBuffer ids = new StringBuffer();
if(questionerIdList.size()==0||questionerIdList==null){
return 0;
}else{
for (int i = 0; i < questionerIdList.size(); i++) {
if (i != 0) {
ids.append(",");
}
ids.append(questionerIdList.get(i));
}
}
//将list转化为以,分隔开的形式的字符串(1,2,3,4,5)
********************************************************************************************
********************************************************************************************
Map params = new HashMap<>();
params.put("ids", ids.toString());
List<ConsultCustomer> cclist = consultCustomerMapper.selectConsultCustomersByCondition(params);
//serviceimpl中调用mapper中方法,并将参数params传进去
select * from 表 where 字段 in (${ids})
// mapper.xml 中sql语句
交集
@org.junit.Test public void add() throws Exception { List<Integer> l1 = new ArrayList<Integer>(); List<Integer> l2 = new ArrayList<Integer>(); List<Integer> l3 = new ArrayList<Integer>(); List<Integer> l4 = new ArrayList<Integer>(); l1.add(1); l1.add(2); l1.add(3); l1.add(4); l1.add(5); l2.add(1); l2.add(2); l2.add(3); l3.add(1); l3.add(3); l3.add(4); l4.add(1); l4.add(2); l4.add(3); l4.add(4); l4.add(5); l4.add(6); l2.retainAll(l1); l2.retainAll(l3); l2.retainAll(l4); System.out.println("----"); System.out.println(l2); }l2.retainAll(l1);
l2.retainAll(l3);
l2.retainAll(l4);
之后的l2即为交集
相关文章推荐
- C# 一个简单的递归函数和 两个List<T> 合并
- python 求两个list的差集,并集和交集
- python两个 list 获取交集,并集,差集的方法
- java-----求两个list的交集、并集、和差集
- Python求两个list的差集、交集与并集的方法(转)
- python两个 list 获取交集,并集,差集的方法
- 两个List取交集,并集,差集
- C#控制台基础 已知两个list<>集合,除去重复后合并成一个
- 在python中如何将两个list合并成一个list,不用for语句
- python 求两个list的差集,并集和交集
- Python求两个list的差集、交集与并集的方法
- Python求两个list的差集、交集与并集的方法
- [LeetCode]Merge Two Sorted Lists & Remove Duplicates from Sorted List 两个有序链表合并为一个&删除链表重复元素
- python 两个list 求交集,并集,差集
- 两个或多个list的交集,并集等的对比(List::Compare)
- Python求两个list的差集、交集与并集的方法
- python取两个list的交集并集差集
- python两个 list 获取交集,并集,差集的方法
- python两个list获取交集,并集,差集
- 两个List合并一个List,去除重复.