Java Collection Union union(Collection initial, Collection other)

Here you can find the source of union(Collection initial, Collection other)

Description

returns a List of union objects, i.e.

License

Apache License

Parameter

Parameter Description
T a parameter
initial a parameter
other a parameter

Declaration

public static <T> List<T> union(Collection<T> initial, Collection<T> other) 

Method Source Code


//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;
    }
}

Related

  1. union(Collection collection1, Collection collection2)
  2. union(Collection c1, Collection c2)
  3. union(Collection> sets)
  4. union(Collection a, Collection b)
  5. union(Collection c1, Collection c2)
  6. union(Collection lhs, Collection rhs)
  7. union(Collection set1, Collection set2)
  8. union(final Collection a, final Collection b)
  9. union(final Collection c1, final Collection c2)