Java tutorial
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { /** * returns a List of union objects, i.e. objects that are present in both collection * * @param <T> * @param initial * @param other * @return */ public static <T> List<T> union(Collection<T> initial, Collection<T> other) { ArrayList<T> union = new ArrayList<T>(); for (T obj : initial) { if (other.contains(obj)) union.add(obj); } return union; } public static boolean contains(Object[] obj, Object value) { for (int i = 0; i < obj.length; i++) { if (obj[i].equals(value)) { return true; } } return false; } public static boolean contains(byte[] obj, byte value) { for (int i = 0; i < obj.length; i++) { if (obj[i] == value) { return true; } } return false; } }