private static List removeAll(List big,List small)throws Exception{
LinkedList link = new LinkedList(big);
HashSet set = new HashSet(small);
Iterator iter = link.iterator();
while(iter.hasNext()){
if(set.contains(iter.next())){
iter.remove();
}
}
return link;
}
有一个大集合List<User> big、一个小集合List<User> small、 从大集合中删除 小集合里的对象(带泛型)
我上面写的方法不行、好像在判断对象是否重复有问题、
请问集合若是带了泛型 用set去重还可以么?
LinkedList link = new LinkedList(big);
HashSet set = new HashSet(small);
Iterator iter = link.iterator();
while(iter.hasNext()){
if(set.contains(iter.next())){
iter.remove();
}
}
return link;
}
有一个大集合List<User> big、一个小集合List<User> small、 从大集合中删除 小集合里的对象(带泛型)
我上面写的方法不行、好像在判断对象是否重复有问题、
请问集合若是带了泛型 用set去重还可以么?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货