我现在得到两个Collection,想对它们做并集和交集操作,怎么解决呢? 自己编程序,把两个collection里面的元素取出来比较,不过这样有点慢!为什么不在sql语句里面做这样的操作呢?这样速度要快得多! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //取并集public Collection getCombination(Collection colA, Collection colB){ HashSet hs = new HashSet(colA); hs.addAll(colB); return hs;}//取交集public Collection getIntersection (Collection colA, Collection colB){ HashSet hs = new HashSet(colA); hs.retainAll(colB); return hs;} 我试了,并集可以,但是交集每次得到的都是null,是不是有问题啊。 没问题的bsd(小红帽菜鸟) 可以实现的 求appfuse大神指导 急求助:EJB中怎样让某个类随容器启动? 求一Mybatis一对一映射例子 Hibernate版本问题 莫明其妙:servlet数据库操作问题 javamail 通信超时 怎么解决? 请问*.jds是什么文件? 对JDOM中XPath使用的不明????请指教..... mysql jdbc中文问题。 java 小的算法问题 成对字符匹配问题 关于Struts的应用 关于编辑器???
public Collection getCombination(Collection colA, Collection colB){
HashSet hs = new HashSet(colA);
hs.addAll(colB);
return hs;
}//取交集
public Collection getIntersection (Collection colA, Collection colB){
HashSet hs = new HashSet(colA);
hs.retainAll(colB);
return hs;
}
bsd(小红帽菜鸟)
可以实现的