Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How to compare two ArrayList for equality in Java?
You can compare two array lists using the equals() method of the ArrayList class, this method accepts a list object as a parameter, compares it with the current object, in case of the match it returns true and if not it returns false.
Example
import java.util.ArrayList;
public class ComparingList {
public static void main(String[] args) {
ArrayList<String> list1 = new ArrayList<String>();
list1.add("JavaFx");
list1.add("Java");
list1.add("WebGL");
list1.add("OpenCV");
ArrayList<String> list2 = new ArrayList<String>();
list2.add("JavaFx");
list2.add("Java");
list2.add("WebGL");
list2.add("OpenCV");
System.out.println(list2);
System.out.println(list1.equals(list2));
}
} Advertisements
