In Java, you can use the Collection interface's removeAll method.

// Create a couple ArrayList objects and populate them
// with some delicious fruits.
Collection firstList = new ArrayList() {{
    add("apple");
    add("orange");
}};

Collection secondList = new ArrayList() {{
    add("apple");
    add("orange");
    add("banana");
    add("strawberry");
}};

// Show the "before" lists
System.out.println("First List: " + firstList);
System.out.println("Second List: " + secondList);

// Remove all elements in firstList from secondList
secondList.removeAll(firstList);

// Show the "after" list
System.out.println("Result: " + secondList);

The above code will produce the following output:

First List: [apple, orange]
Second List: [apple, orange, banana, strawberry]
Result: [banana, strawberry]
Answer from William Brendel on Stack Overflow
🌐
How to do in Java
howtodoinjava.com › home › collections framework › java arraylist › compare two lists in java: equality, differences, common items
Compare Two Lists in Java: Equality, Differences, Common Items
1 week ago - Java ArrayList · Two lists in ... sorted copies or element counts, and to find the differences, we call removeAll() and retainAll() on a copy of one list....
🌐
Baeldung
baeldung.com › home › java › java list › finding the differences between two lists in java
Finding the Differences Between Two Lists in Java | Baeldung
April 29, 2026 - List<String> differences = new ArrayList<>(listTwo); differences.removeAll(listOne); assertEquals(3, differences.size()); assertThat(differences).containsExactly("Daniel", "Alan", "George"); We should also note that if we want to find the common ...
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › how-to-compare-two-arraylist-in-java
How to compare two ArrayList in Java
"Yes" : "No"); System.out.println(al3); //Storing the comparison output in ArrayList<Integer> ArrayList<Integer> al4= new ArrayList<Integer>(); for (String temp2 : al1) al4.add(al2.contains(temp2) ?
🌐
DevQA
devqa.io › java-compare-two-arraylists
Java Compare Two Lists
March 17, 2020 - The List interface also provides methods to find differences between two lists. The removeAll() method compares two lists and removes all the common items. What’s left is the additional or missing items.
🌐
Javatpoint
javatpoint.com › how-to-compare-two-arraylist-in-java
How to Compare Two ArrayList in Java - Javatpoint
getLast() iterator() offerFirst() offerLast() offer() peek() peekFirst() peekLast() pollFirst() pollLast() poll() pop() Java Long class · Java LinkedTransferQueue · add() contains() isEmpty() iterator() offer() remove() size() spliterator() drainTo() peek() poll() put() take() Difference between Array and ArrayList · When to use ArrayList and LinkedList in Java · Difference between ArrayList and Vector · How to Compare Two ArrayList in Java ·
🌐
TutorialsPoint
tutorialspoint.com › comparing-two-arraylist-in-java
Check two ArrayList for equality in Java
June 18, 2024 - Find the perfect tutorial for your learning journey · Two ArrayList can be compared to check if they are equal or not using the method java.util.ArrayList.equals(). This method has a single parameter i.e. an ArrayList that is compared with the current object.
Find elsewhere
🌐
CodingTechRoom
codingtechroom.com › question › how-to-compute-difference-two-arraylists-java
How to Compute the Difference Between Two ArrayLists in Java - CodingTechRoom
To calculate the difference between two ArrayLists in Java, we need to determine which elements are in the selected list but not in the original list (elements to add) and which elements are in the original list but not in the selected list (elements to remove).
🌐
Coderanch
coderanch.com › t › 588750 › java › Find-difference-String-ArrayLists-Java
Find the difference between 2 String ArrayLists in Java (Java in General forum at Coderanch)
August 1, 2012 - There is a combined class, LinkedHashSet. Put the two Lists into LinkedHashSets, carry out the ∪∩ etc., and use the resultant linked set’s iterator to reload an ArrayList. You can find out about the bulk methods in the Set interface and the Java Tutorials.
🌐
Stack Overflow
stackoverflow.com › questions › 22794338 › compare-two-different-arraylists-and-get-differences-java
android - Compare two different arraylists and get differences java - Stack Overflow
... You should look at using Sets for this. Drop all the items from one array into a HashSet and then loop over the other array checking if it is contained in the Set. This will be much faster than looping over an ArrayList each time.
🌐
GeeksforGeeks
geeksforgeeks.org › java › comparing-two-arraylist-in-java
Comparing two ArrayList In Java - GeeksforGeeks
January 23, 2026 - In Java, an ArrayList is used to store an ordered collection of elements. To compare two ArrayList objects, Java provides the equals() method.
🌐
YouTube
youtube.com › naveen automationlabs
#7 - How to Compare Two ArrayLists in Java - YouTube
In this video, I have explained how to compare two ArrayLists in Java.Learn:1. Compare two ArrayList using Sort and Equals methods.2. Find out the additional...
Published: October 19, 2020
Views: 52K
🌐
DEV Community
dev.to › aryan19694946 › how-to-compare-two-arraylist-in-java-499b
How to compare two ArrayList in Java? - DEV Community
March 19, 2020 - public class ArrayListExample { public static void main(String[] args) { ArrayList list1 = new ArrayList(); list1.add("A"); list1.add("B"); list1.add("C"); list1.add("D"); ArrayList list2 = new ArrayList(); list2.add("A"); list2.add("B"); list2.add("C"); list2.add("D"); System.out.println(list2); System.out.println(list1.equals(list2)); } } If you want to learn in detail: https://www.java8net.com/2020/03/compare-two-arraylist-in-java.html
🌐
TutorialsPoint
tutorialspoint.com › article › How-to-compare-two-ArrayList-for-equality-in-Java
How to compare two ArrayList for equality in Java?
July 30, 2019 - 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.
🌐
Javaprogramto
javaprogramto.com › 2020 › 04 › how-to-compare-two-arraylist-for-equality-in-java.html
How to compare two ArrayList for equality in Java 8? ArrayList equals() or containsAll() methods works?
June 13, 2021 - A quick program to compare two list values inside the lists. This equality check is done using the ArrayList equals() method and containsAll() method. Java 8 Stream API Example as well.