Java tutorial
//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 { /** * * @param container the containing collection * @param contained the collection with a contained element * @return true if container contains any of the elements in contained. * this is the same as asking if the collections intersect. * the terminology is just because it's sometimes easier to think of it this way. */ public static boolean containsAny(Collection container, Collection contained) { Collection copy = intersect(container, contained); return !copy.isEmpty(); } /** * * @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; } }