Answer the question
In order to leave comments, you need to log in
How to remove all elements from the first list from the second list?
For example I have
import java.util.LinkedList;
public class Main {
public static void main(String[] args) {
LinkedList<Character> first = new LinkedList<>(); // first = ['A', 'B', 'B', 'A']
LinkedList<Character> second = new LinkedList<>(); // second = ['B', 'A']
}
}
Answer the question
In order to leave comments, you need to log in
Here is some java8 if you don't tolerate cycles
List<String> listA = new ArrayList<String>(){{
add("A");
add("B");
add("C");
add("B");
add("A");
}};
List<String> listB = new ArrayList<String>(){{
add("A");
add("B");
}};
listA.removeIf(s -> {
if (listB.contains(s)) {
listB.remove(s);
return true;
}
return false;
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question