Here you can find the source of intersectionSize(Collection c1, Collection c2)
Parameter | Description |
---|---|
c1 | a collection |
c2 | a collection |
public static int intersectionSize(Collection c1, Collection c2)
//package com.java2s; /* Copyright (c) 2010, Johannes K?ster <johannes.koester@tu-dortmund.de> * All rights reserved./*from w w w. ja va 2 s. co m*/ * * This software is open-source under the BSD license; see "license.txt" * for a description. */ import java.util.Collection; public class Main { /** * Calculate the size of intersection between two collections. * * @param c1 a collection * @param c2 a collection * @return the size of intersection */ public static int intersectionSize(Collection c1, Collection c2) { int size = 0; if (c1.size() < c2.size()) { for (Object o : c1) { if (c2.contains(o)) { size++; } } } else { for (Object o : c2) { if (c1.contains(o)) { size++; } } } return size; } }