Java Utililty Methods List Intersect

List of utility methods to do List Intersect

Description

The list of methods to do List Intersect are organized into topic(s).

Method

voidintersect(List lst1, List lst2)
intersect
for (int i = 0; i < lst1.size(); i++) {
    Object obj1 = lst1.get(i);
    if (!lst2.contains(obj1))
        lst1.remove(i--);
Listintersect(List list1, List list2)
This method returns a new ArrayList which is the intersection of the two List parameters, based on Object#equals(Object) equality of their elements.
if (list1 == null || list1.isEmpty() || list2 == null || list2.isEmpty()) {
    return Collections.emptyList();
List<T> result = new ArrayList<T>();
result.addAll(list1);
result.retainAll(list2);
return result;
Listintersect(List... lists)
Returns a set intersection of the given lists.
List<E> results = create();
boolean seeded = false;
for (List<E> list : lists) {
    if (list != null) {
        if (seeded) {
            results.retainAll(list);
        } else {
            results.addAll(list);
...
Listintersect(List in1, List in2)
intersect
final List<T> theResults = new ArrayList<T>(0);
if (in1 == null || in2 == null || in1.isEmpty() || in2.isEmpty()) {
    return theResults;
for (final T anObject : in1) {
    if (anObject == null && in2.contains(null)) {
        theResults.add(anObject);
    } else if (anObject != null && in2.contains(anObject)) {
...
booleanintersect(Set a, List b)
intersect
return intersect(a, (Iterable<?>) b);
Listintersect2orderedList(List s1, List s2)
Computes the intersection of 2 integer ordered lists.
if (s1.size() > s2.size())
    return intersect2orderedList(s2, s1);
List<Integer> res = new ArrayList<Integer>();
int pos1 = 0, pos2 = 0;
while (pos1 < s1.size() && pos2 < s2.size()) {
    if (s1.get(pos1).equals(s2.get(pos2))) {
        res.add(s1.get(pos1));
        pos1++;
...
voidintersectAll(final List collector, final T[] a, final T[] b)
Intersects the two given arrays in bag logic.
int index1 = 0;
int index2 = 0;
while (true) {
    if (index1 >= a.length || index2 >= b.length) {
        break;
    } else {
        final T candidate1 = a[index1];
        final T candidate2 = b[index2];
...
ListintersectDate(List oDate, List tDate)
intersect Date
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
List<Date> listDate = new ArrayList<Date>();
for (Date wDate : oDate) {
    for (Date iDate : tDate) {
        String strWDate = sdf.format(wDate).toString();
        String strIDate = sdf.format(iDate).toString();
        if (strWDate.equals(strIDate)) {
            listDate.add(wDate);
...
Listintersection(final List list1, final List list2)
Returns a new list containing all elements that are contained in both given lists.
final ArrayList result = new ArrayList();
final Iterator iterator = list2.iterator();
while (iterator.hasNext()) {
    final Object o = iterator.next();
    if (list1.contains(o))
        result.add(o);
return result;
...
Listintersection(final List list1, final List list2)
Returns a new list containing all elements that are contained in both given lists.
final ArrayList result = new ArrayList();
final Iterator iterator = list2.iterator();
while (iterator.hasNext()) {
    final Object o = iterator.next();
    if (list1.contains(o)) {
        result.add(o);
return result;