Returns the intersection of two sets without modifying the original sets.<p>

@param <A> the type of objects contained in the sets

@param first the first set
@param second the second set

@return the intersection of both sets
429455
public static <A> Set<A> intersection(Set<A> first, Set<A> second) {

        HashSet<A> result = new HashSet<A>(first);
        result.retainAll(second);
        return result;
    }
564012
public static final boolean intersection(Rectangle src1, Rectangle src2, Rectangle dest)
    {
        int x1 = Math.max(src1.x, src2.x);
        int y1 = Math.max(src1.y, src2.y);
        int x2 = Math.min(src1.x + src1.width, src2.x + src2.width);
        int y2 = Math.min(src1.y + src1.height, src2.y + src2.height);
        dest.setBounds(x1, y1, x2 - x1, y2 - y1);

        if (dest.width <= 0 || dest.height <= 0)
            return false;

        return true; // non-empty intersection
    }
1184467
public Range<T> intersectionWith(Range<T> other) {
    if (!this.isOverlappedBy(other)) { throw new IllegalArgumentException(String.format(
        "Cannot calculate intersection with non-overlapping range %s", other)); }
    if (this.equals(other)) { return this; }
    T min = this.comparator.compare(this.min, other.min) < 0 ? other.min : this.min;
    T max = this.comparator.compare(this.max, other.max) < 0 ? this.max : other.max;
    return between(min, max, this.comparator);
  }
666582
public static <T> Collection<T> intersection(Collection<T> coll1, Collection<T> coll2) {
		final ArrayList<T> list = new ArrayList<>();
		if (isNotEmpty(coll1) && isNotEmpty(coll2)) {
			final Map<T, Integer> map1 = countMap(coll1);
			final Map<T, Integer> map2 = countMap(coll2);
			final Set<T> elts = newHashSet(coll2);
			int m;
			for (T t : elts) {
				m = Math.min(Convert.toInt(map1.get(t), 0), Convert.toInt(map2.get(t), 0));
				for (int i = 0; i < m; i++) {
					list.add(t);
				}
			}
		}
		return list;
	}
1007499
public static <T extends Comparable<T>> int compareLists(List<T> list1, List<T> list2) {
    if (list1 == null && list2 == null)
      return 0;
    if (list1 == null || list2 == null) {
      throw new IllegalArgumentException();
    }
    int size1 = list1.size();
    int size2 = list2.size();
    int size = Math.min(size1, size2);
    for (int i = 0; i < size; i++) {
      int c = list1.get(i).compareTo(list2.get(i));
      if (c != 0)
        return c;
    }
    if (size1 < size2)
      return -1;
    if (size1 > size2)
      return 1;
    return 0;
  }
29438
def intersection (set1, set2):
    
    assert is_iterable(set1)
    assert is_iterable(set2)
    result = []
    for v in set1:
        if v in set2:
            result.append (v)
    return result
420560
public static String[] intersect(
      Comparator<? super String> comparator, String[] first, String[] second) {
    List<String> result = new ArrayList<>();
    for (String a : first) {
      for (String b : second) {
        if (comparator.compare(a, b) == 0) {
          result.add(a);
          break;
        }
      }
    }
    return result.toArray(new String[0]);
  }
7850
public static <E> Set<E> difference(Set<? extends E> s1, Set<? extends E> s2) {
      Set<E> copy1 = new HashSet<>(s1);
      copy1.removeAll(new HashSet<>(s2));
      return copy1;
   }
1156608
public double distance(Instance first, Instance second) {
    return distance(first, second, Double.POSITIVE_INFINITY);
  }
508337
public static NumericalValue intersect (final NumericalValue a, final NumericalValue b) {
        // early exit
        if (a == null || b == null) return null;
        // get ranges of a and b
        int aMin, aMax, bMin, bMax;
        if (a instanceof SingleNumericalValue) {
            final SingleNumericalValue v = (SingleNumericalValue) a;
            aMin = v.getValue();
            aMax = aMin;
        } else {
            final NumericalValueRange r = (NumericalValueRange) a;
            aMin = r.getMin();
            aMax = r.getMax();
        }
        if (b instanceof SingleNumericalValue) {
            final SingleNumericalValue v = (SingleNumericalValue) b;
            bMin = v.getValue();
            bMax = bMin;
        } else {
            final NumericalValueRange r = (NumericalValueRange) b;
            bMin = r.getMin();
            bMax = r.getMax();
        }
        // intersect ranges
        final int min = Math.max(aMin, bMin);
        final int max = Math.min(aMax, bMax);
        if (min == max)
            return SingleNumericalValue.create(min);
        else
            return NumericalValueRange.create(min, max);
    }
1345541
public static <T> Set<T> intersection(Collection<Set<T>> sets) {
		Set<T> result = new HashSet<>();
		if (sets.isEmpty()) {
			return result;
		}
		Iterator<Set<T>> iter = sets.iterator();
		result.addAll(iter.next());
		while (iter.hasNext()) {
			result.retainAll(iter.next());
		}
		return result;
	}
315340
def intersection(self,other):
        
        if self.everything:
            if other.everything:
                return DiscreteSet()
            else:
                return DiscreteSet(other.elements)
        else:
            if other.everything:
                return DiscreteSet(self.elements)
            else:
                return DiscreteSet(self.elements.intersection(other.elements))
141504
public static <T> Predicate<T> and(Predicate<T> first, Predicate<T> second) {
        dbc.precondition(first != null, "first predicate is null");
        dbc.precondition(second != null, "second predicate is null");
        return Logic.Unary.and(Iterations.iterable(first, second));
    }
919589
public HashMap<K2, HashMap<K3, V>> get(final K1 firstKey) {
		return map.get(firstKey);
	}
1135948
function intersection( arr1, arr2 ){
	var rtn = [];

	if ( arr1.length > arr2.length ){
		let t = arr1;

		arr1 = arr2;
		arr2 = t;
	}

	for( let i = 0, c = arr1.length; i < c; i++ ){
		let d = arr1[i];

		if ( arr2.indexOf(d) !== -1 ){
			rtn.push( d );
		}
	}

	return rtn;
}
115543
public static <T> List<T> intersection(List<T> arr1, List<T> arr2) {
        return intersection(arr1, 0, arr1.size(), arr2, 0, arr2.size());
    }
1038661
public static IntSet difference (IntSet set1, IntSet set2)
    {
        return and(set1, notView(set2));
    }