How to compare two ArrayList and get list1 with filter using java streams
问题 I have two lists list1 & list2 of type List Term{ long sId; int rowNum; long psid; String name; } List<Term> list1 = new ArrayList<>(); List<Term> list2 = new ArrayList<>(); I want to return all the items from list1 where (list1.psid != list2.psid). I tried this but its not working public List<Term> getFilteredRowNum(List<Term> list1, List<Term> list2) { List<Long> psid = list2.stream().map(x -> x.getPsid()).collect(Collectors.toList()); return list1.stream().filter(x -> !psid.contains(x