Skip to content
Advertisement

Duplication on ArrayList Java

my title is bad but I don’t have an idea what it should be. My question is simple, I have four arraylist and I want to get similar words from two of them and put another arraylists. Anyway my array lists like;

JavaScript

I tried this;

JavaScript

But as you see arrList1 and arrList2 have duplicates so arrList4 will have same element more than normal. Also I have to count elements which are in arrList1 and arrList2 so I shouldn’t use Set Collections. What should I do?

Advertisement

Answer

Try

JavaScript

This will check if the new ArrayList does not already contain the item.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement