R
R
RapperOfGods2017-03-22 17:40:53
Java
RapperOfGods, 2017-03-22 17:40:53

Is there a function in java to remove identical elements in a list?

Good afternoon. I have 2 lists (List), can I remove from the first list all the elements that are in the second? Or rather, is there such a function in java so as not to write a bicycle yourself?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Oparin, 2017-03-22
@RapperOfGods

List<String> list1 = new ArrayList<>();
List<String> list2 = new ArrayList<>();
list1.add("1");
list1.add("2");
list1.add("3");

list2.add("3");
list2.add("4");
list2.add("5");

list1.removeAll(list2);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question