- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 remove duplicates from an ArrayList in Java?
In Java, Set object does not allow duplicate elements so you can remove duplicates from a list by creating a set object by passing required List object to its constructor.
Example:
import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.Set; public class ArrayListSample { public static void main(String[] args){ ArrayList<String> list = new ArrayList<String>(); list.add("JavaFx"); list.add("Java"); list.add("WebGL"); list.add("OpenCV"); Set<String> set = new LinkedHashSet<String>(list); System.out.println(set); } }
Output:
[JavaFx, Java, WebGL, OpenCV]
- Related Articles
- How to remove an element from ArrayList in Java?
- How to remove a SubList from an ArrayList in Java?
- How to remove an element from ArrayList or, LinkedList in Java?
- Java Program to Remove Duplicates from an Array List
- How to remove element from ArrayList in Java?
- Remove duplicate items from an ArrayList in Java
- How to remove the redundant elements from an ArrayList object in java?
- Java Program to Remove Repeated Element from An ArrayList
- How to remove an item from an ArrayList in C#?
- How to remove an item from an ArrayList in Kotlin?
- Remove an element from an ArrayList using the ListIterator in Java
- Golang Program To Remove Duplicates From An Array
- How to remove duplicates from MongoDB Collection?
- Java Program to Remove duplicate elements from ArrayList
- Java program to remove duplicates elements from a List

Advertisements