Java List Equal isEqual(List from, List to)

Here you can find the source of isEqual(List from, List to)

Description

is Equal

License

LGPL

Declaration

public static <E extends Object> boolean isEqual(List<E> from,
            List<E> to) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.util.ArrayList;
import java.util.Collection;

import java.util.List;

public class Main {
    public static <E extends Object> boolean isEqual(List<E> from,
            List<E> to) {//from   ww  w . ja va 2 s.c o m
        return (getCommonElements(from, to).size() == from.size())
                && (from.size() == to.size());
    }

    public static <E extends Object> List<E> getCommonElements(
            List<E> from, List<E> to) {
        List<E> res = new ArrayList<E>();
        for (int i = 0; i < from.size(); i++) {
            if (hasElement(to, from.get(i))) {
                res.add(from.get(i));
            }
        }
        return res;
    }

    public static <E extends Object> List<E> getCommonElements(
            List<List<E>> sets) {
        List<E> set = getCommonElements(sets.get(0), sets.get(1));
        for (int i = 2; i < sets.size(); i++) {
            set = getCommonElements(set, sets.get(i));
        }
        return set;
    }

    public static <E extends Object> List<E> getCommonElements(
            Collection<E> from, Collection<E> to) {
        List<E> res = new ArrayList<E>();
        for (E f : from) {
            for (E t : to) {
                if (f.equals(t)) {
                    res.add(f);
                }
            }
        }
        return res;
    }

    public static <E extends Object> boolean hasElement(List<E> array,
            E element) {
        boolean res = false;
        for (int i = 0; i < array.size(); i++) {
            if (array.get(i).equals(element)) {
                res = true;
                break;
            }
        }
        return res;
    }
}

Related

  1. equalsAny(String toMatch, List matchesAny)
  2. equalsBasedOnEntryIdentity(final List a, final List b)
  3. equalShallow(List list0, List list1)
  4. isEqual(Collection listA, Collection listB)
  5. isEqual(List list1, List list2)
  6. isEqualAsMultiset(List left, List right)
  7. isEqualIgnoringOrder(List left, List right)
  8. isEqualList(List list1, List list2)
  9. isEquals(List l1, List l2)