Java Collection Contain intersect(Collection container, Collection contained)

Here you can find the source of intersect(Collection container, Collection contained)

Description

intersect

License

Open Source License

Parameter

Parameter Description
container a collection
contained another collection

Return

an intersection

Declaration

public static Collection intersect(Collection container, Collection contained) 

Method Source Code


//package com.java2s;
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

import java.util.*;

public class Main {
    /**/*from  w w  w. jav  a  2 s.c  o  m*/
     *
     * @param container a collection
     * @param contained another collection
     * @return an intersection
     */
    public static Collection intersect(Collection container, Collection contained) {

        Collection copy = new ArrayList(container);
        copy.retainAll(contained);

        return copy;
    }
}

Related

  1. containsSome(HashSet s1, Collection other)
  2. containsString(Collection coll, String str)
  3. containsString(String stringToCheck, Collection collection)
  4. containsStringIgnoreCase(Collection strings, String toCheck)
  5. getContainmentRelation(Collection a, Collection b)
  6. isAnyElementContains(String str, Collection col)
  7. isContained(Collection container, String strSearch)
  8. isNullOrContains(final Collection collection, final T item)
  9. stringContainsOneOfStringsFromCollection(final String pattern, final Collection collection)