I have two ArrayList
objects with three integers each. I want to find a way to return the common elements of the two lists. Has anybody an idea how I can achiev
List listA = new ArrayList<>();
listA.add(1);
listA.add(5);
listA.add(3);
listA.add(4);
List listB = new ArrayList<>();
listB.add(1);
listB.add(5);
listB.add(6);
listB.add(7);
System.out.println(listA.stream().filter(listB::contains).collect(Collectors.toList()));
Java 1.8 Stream API Solutions
Output [1, 5]