Java Collection Intersect intersect(Collection c1, Collection c2)

Here you can find the source of intersect(Collection c1, Collection c2)

Description

intersect

License

Open Source License

Declaration

@SuppressWarnings({ "rawtypes", "unchecked" })
public static List intersect(Collection c1, Collection c2) 

Method Source Code


//package com.java2s;
import java.util.ArrayList;

import java.util.Collection;
import java.util.List;
import java.util.Map;

public class Main {

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static List intersect(Collection c1, Collection c2) {
        List c1_ = new ArrayList();
        List c1__ = new ArrayList();
        if (isNotEmpty(c1)) {
            c1_.addAll(c1);/*from w  w w .j  a  va  2 s  . co m*/
            c1__.addAll(c1);
            c1__.removeAll(c2);
            c1_.removeAll(c1__);
        }

        return c1_;
    }

    @SuppressWarnings("rawtypes")
    public static boolean isNotEmpty(Map map) {
        return !isEmpty(map);
    }

    @SuppressWarnings("rawtypes")
    public static boolean isNotEmpty(Collection collection) {
        return !isEmpty(collection);
    }

    public static boolean isNotEmpty(Object[] objs) {
        return !isEmpty(objs);
    }

    @SuppressWarnings("rawtypes")
    public static boolean isEmpty(Map map) {
        if (map == null || map.size() == 0) {
            return true;
        }
        return false;
    }

    @SuppressWarnings("rawtypes")
    public static boolean isEmpty(Collection collection) {
        if (collection == null || collection.size() == 0) {
            return true;
        }
        return false;
    }

    public static boolean isEmpty(Object[] objs) {
        if (objs == null || objs.length == 0) {
            return true;
        }
        return false;
    }
}

Related

  1. hasIntersection(Collection s1, Collection s2)
  2. hasIntersection(Collection a, Collection b)
  3. hasIntersection(Collection c1, Collection c2)
  4. hasIntersection(Collection col1, Collection col2)
  5. hasIntersection(final Collection a, final Collection b)
  6. intersect(Collection c1, Collection c2)
  7. intersect(Collection collection, Collection otherCollection)
  8. intersect(Collection... collections)
  9. intersect(Collection a, Collection b)