Remove duplicate elements from an ArrayList in Java

0 votes
How can I eliminate duplicate elements from Java ArrayList
Apr 30, 2018 in Java by developer_1
• 3,350 points
1,708 views

2 answers to this question.

0 votes

You can perform this task by performing the following:

arrayList = new ArrayList<String>(new LinkedHashSet<String>(arrayList));
answered May 1, 2018 by sharth
• 3,370 points
0 votes
List<String> al = new ArrayList<>();
// add elements to al, including duplicates
Set<String> hs = new HashSet<>();
hs.addAll(al);
al.clear();
al.addAll(hs);
answered Jul 26, 2018 by Sushmita
• 6,920 points

Related Questions In Java

0 votes
1 answer

Remove duplicates from an ArrayList in Java

Here is the function for doing this. // ...READ MORE

answered Mar 6, 2019 in Java by Heena
4,280 views
0 votes
2 answers

How can we remove an element from an array in Java?

You can use ArrayUtils class remove method ...READ MORE

answered May 24, 2018 in Java by UshaK
2,770 views
0 votes
0 answers
0 votes
2 answers

One line initialization of an ArrayList object in Java

In Java 8 or earlier: List<String> string = ...READ MORE

answered Jul 26, 2018 in Java by samarth295
• 2,220 points
4,811 views
+1 vote
1 answer

Remove objects from an array in Java?

We can use external libraries: org.apache.commons.lang.ArrayUtils.remove(java.lang.Object[] array, int ...READ MORE

answered Jun 26, 2018 in Java by scarlett
• 1,290 points
1,209 views
0 votes
1 answer

Sorting an ArrayList in Java

You can easily do this by simply ...READ MORE

answered May 5, 2018 in Java by geek.erkami
• 2,680 points
2,208 views
0 votes
1 answer

How do I join 2 lists

This is not a simpler method, but ...READ MORE

answered May 11, 2018 in Java by sharth
• 3,370 points
814 views
0 votes
1 answer

Convert comma-separated String to ArrayList?

List<String> alist = Arrays.asList(str.split("\\s*,\\s*")); The above code splits ...READ MORE

answered May 17, 2018 in Java by sharth
• 3,370 points
3,389 views
0 votes
1 answer

How can I Sort an ArrayList in Java

You can sort the ArrayList in 2 ...READ MORE

answered Apr 23, 2018 in Java by sharth
• 3,370 points
880 views
0 votes
2 answers

When to use LinkedList and ArrayList in Java?

ArrayList is what you want. LinkedList is almost always a ...READ MORE

answered Dec 11, 2018 in Java by Sushmita
• 6,920 points
1,165 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP