how to compare two arraylists are equal in java

Solutions on MaxInterview for how to compare two arraylists are equal in java by the best coders in the world

showing results for - "how to compare two arraylists are equal in java"
Sophie
19 Nov 2016
1public class ArrayListExample 
2{
3    public static void main(String[] args) 
4    {
5        ArrayList<String> listOne = new ArrayList<>(Arrays.asList("a", "b", "c", "d", "f"));
6         
7        ArrayList<String> listTwo = new ArrayList<>(Arrays.asList("a", "b", "c", "d", "e"));
8         
9        Collections.sort(listOne);
10        Collections.sort(listTwo);
11         
12        //Compare unequal lists example
13         
14        boolean isEqual = listOne.equals(listTwo);      //false
15        System.out.println(isEqual);
16         
17        //Compare equals lists example
18         
19        ArrayList<String> listThree = new ArrayList<>(Arrays.asList("a", "b", "c", "d", "f"));
20         
21        isEqual = listOne.equals(listThree);      //true
22        System.out.println(isEqual);
23    }
24}
25
queries leading to this page
compare elements of two arraylist in javajava check if two arraylists are equalhow to compare two values in the same arraylist in javacompare two arraylist in java 8check equality of two arraylisthow to compare arraylistscompare two arrayslisthow to compare within an arraylistcomparing two arraylist in javacompare contants arraylist in javahow to compare two unequal arraylist in javahow to compare two arraylist of different objects in javacompare 2 arraylistshow to compare two arraylistshow to compare values of two arraylist in javahow to compare an object in arraylisthow to compare inside an arraylistcompare two arraylist in javajava compare arraylists for equalitycheck if two arraylist are equal javacompare every value inside java arraylisthow to compare two arraylist in java and find differencehow to compare two arraylists are equal in javajava compare array and arraylistcheck if 2 arraylists are equal javajava compare arraylistshow to compare two arraylist in java using comparatorcompare 2 arraylistcompare two arraylists javacheck if two arraylists are equal javacompare two arraylistshow to compare string object in arraylist oophow to compare two arraylist in androidhow to compare two different arraylist in javacomparing two arraylists in java2 arraylist comparehow compare two arraylist in javahow to compare two arraylist in javahow to compare two arraylist and choose the bigger one javahow to compare two arraylist in node jshow to compare values in two arraylist in javahow to compare string in arraylist oophow to compare two values in arraylist in javacompare two arraylist elements in javajava method to compare values of 2 arraylistjava 8 compare two arraylist compare 2 values in arraylist javacompare element of two arraylist in jvaahow to check if two arraylists are equal javacomparing elements of two arraylists in javacompare two arraylist in android studiohow to compare two arraylistss of integers javacompare two arraylist in javahow to check if two arraylists are equal in javahow to compare two values in an arraylist in javahow to compare two arraylist in javecomparing contents of two arraylists in javacompare two arraylist in javascripthow to compare two arraylists are equal in java