VOOZH about

URL: https://www.geeksforgeeks.org/java/list-equals-method-in-java-with-examples/

⇱ List equals() Method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

List equals() Method in Java with Examples

Last Updated : 3 Jan, 2025

The List equals() method is used to compare two lists. It compares the lists as, both lists should have the same size, and all corresponding pairs of elements in the two lists are equal.

Implementation:


Output
Equal

Syntax of List equals() Method

boolean equals(Object o)

  • Parameters: This function has a single parameter which is object to be compared for equality.
  • Returns: This method returns True if lists are equal.

Example of List equals() Method

Below programs show the implementation of this method.

Program 1: (Demonstrate different Type in Collection - ArrayList and LinkedList)


Output
[10, 15, 20]
[100, 200, 300]
Not equal

Program 2: The Case where values are equal.


Output
[10, 15, 20]
[10, 15, 20]
Equal
Comment