The Java List equals method is used to compare two lists for equality. It returns true if both lists contain the same elements in the same order, otherwise it returns false.
Example 1: List list1 = new ArrayList<>(Arrays.asList(1, 2, 3)); List list2 = new ArrayList<>(Arrays.asList(1, 2, 3)); boolean isEqual = list1.equals(list2); // isEqual is true as both lists contain the same elements in the same order
Example 2: List list1 = new LinkedList<>(Arrays.asList("apple", "banana", "cherry")); List list2 = new LinkedList<>(Arrays.asList("apple", "banana", "orange")); boolean isEqual = list1.equals(list2); // isEqual is false as both lists contain different elements
This method is part of the Java Collections framework and is available in the java.util package.
Java List.equals - 30 examples found. These are the top rated real world Java examples of List.equals from package OpenDSA-server extracted from open source projects. You can rate examples to help us improve the quality of examples.