List equals Regardless Of Order - Java java.util

Java examples for java.util:List Operation

Description

List equals Regardless Of Order

Demo Code


//package com.java2s;

import java.util.List;

public class Main {
    public static void main(String[] argv) {
        List lst = java.util.Arrays.asList("asdf", "java2s.com");
        List lst2 = java.util.Arrays.asList("asdf", "java2s.com");
        System.out.println(equalsRegardlessOfOrder(lst, lst2));
    }//from   w ww  . j a  va2s  .c  o  m

    public static boolean equalsRegardlessOfOrder(
            List<? extends Object> lst, List<? extends Object> lst2) {
        if (lst == null || lst2 == null) {
            return lst == lst2;
        }

        return (lst.containsAll(lst2) && lst2.containsAll(lst));
    }
}

Related Tutorials