Java工具类(25)—比较两个集合方法
public static <E> List<E> getAddaListThanbList(List<E> aList, List<E> bList) {
List<E> addList = new ArrayList<E>();
for (int i = 0; i < aList.size(); i++) {
if (!myListContains(bList, aList.get(i))) {
addList.add(aList.get(i));
}
}
return addList;
}
public static <E> List<E> getReduceaListThanbList(List<E> aList, List<E> bList) {
List<E> reduceaList = new ArrayList<E>();
for (int i = 0; i < bList.size(); i++) {
if (!myListContains(aList, bList.get(i))) {
reduceaList.add(bList.get(i));
}
}
return reduceaList;
}
private static <E> boolean myListContains(List<E> sourceList, E element) {
if (sourceList == null || element == null) {
return false;
}
if (sourceList.isEmpty()) {
return false;
}
for (E tip : sourceList) {
if (element.equals(tip)) {
return true;
}
}
return false;
}