Here you can find the source of union(Collection
Parameter | Description |
---|---|
T | a parameter |
initial | a parameter |
other | a parameter |
public static <T> List<T> union(Collection<T> initial, Collection<T> other)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { /**/* www . j ava 2 s .co m*/ * 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; } }