

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)); } }
- Related Questions & Answers
- Check two ArrayList for equality in Java
- How to compare two lists for equality in C#?
- Java Program to compare strings for equality
- How to compare String equality in Java?
- Check two numbers for equality in Java
- Check two HashMap for equality in Java
- Check two float arrays for equality in Java
- Compare array elements to equality - JavaScript
- How to Compare two String in Java?
- How to compare two arrays in Java?
- How to compare two dates in Java?
- Java Program to check for equality between two strings ignoring the case
- Compare two Strings in Java
- Java Program to Compare Two Strings
- Java Program to compare two sets
Advertisements