Check if two lists are equal Based On Entry Identity - Java java.util

Java examples for java.util:List Search

Description

Check if two lists are equal Based On Entry Identity

Demo Code


//package com.java2s;
import java.util.List;

public class Main {
    public static void main(String[] argv) {
        List a = java.util.Arrays.asList("asdf", "java2s.com");
        List b = java.util.Arrays.asList("asdf", "java2s.com");
        System.out.println(equalsBasedOnEntryIdentity(a, b));
    }/*from  w ww .  j  av  a  2s.c  o m*/

    public static <T> boolean equalsBasedOnEntryIdentity(final List<T> a,
            final List<T> b) {
        if (a == b) {
            return true;
        }

        if (a == null || b == null) {
            return false;
        }

        final int aSize = a.size();
        final int bSize = b.size();

        if (aSize == bSize) {
            for (int i = 0; i < aSize; i++) {
                if (a.get(i) != b.get(i)) {
                    return false;
                }
            }

            return true;
        }

        return false;
    }
}

Related Tutorials