Java List Intersect hasIntersection(Set set, List list)

Here you can find the source of hasIntersection(Set set, List list)

Description

Check if there is an intersection between the set and the list.

License

BSD License

Parameter

Parameter Description
set A given set.
list A given list.
T Type of the objects in set or list.

Return

True if there is an intersection. False otherwise.

Declaration

public static <T> boolean hasIntersection(Set<T> set, List<T> list) 

Method Source Code


//package com.java2s;
/*/*from www  . j  av a  2s  .co m*/
 * This file is released under terms of BSD license
 * See LICENSE file for more information
 */

import java.util.*;

public class Main {
    /**
     * Check if there is an intersection between the set and the list.
     *
     * @param set  A given set.
     * @param list A given list.
     * @param <T>  Type of the objects in set or list.
     * @return True if there is an intersection. False otherwise.
     */
    public static <T> boolean hasIntersection(Set<T> set, List<T> list) {
        for (T n : set) {
            if (list.contains(n)) {
                return true;
            }
        }
        return false;
    }
}

Related

  1. getIntersection( final List... collectionOfIDLists)
  2. getIntersection(List list1, List list2)
  3. getIntersection(String[] list1, String[] list2)
  4. getIntersectionOfLineAndSegments(double x1, double y1, double x2, double y2, List segmentPoints)
  5. hasIntersection(List list1, List list2)
  6. Intersect(List A, List B)
  7. intersect(List ls, List ls2)
  8. intersect(List lst1, List lst2)
  9. intersect(List list1, List list2)