Map<Integer, Boolean> map1= new HashMap<>();
map1.put(1, true);
map1.put(2, true);
map1.put(3, false);
map1.put(4, true);
map1.put(5, false);
Map<Integer, Integer> map2= new HashMap<>();
map2.put(1, 1);
map2.put(2, 2);
map2.put(3, 3);
map2.put(4, 4);
map2.put(5, 5);
List<Integer> valids = new ArrayList<>();
map2.values().stream().filter(value-> map1.get(value) ? valids.add(account) : false);
When I try to output the values of the list valids it returns an empty list. Why is it so? Does the reference of the list change when doing the stream operation?
Note :I am able to add to it using the collect() method.
map1.get(value) ? trues.add(account) : falseis the same asmap1.get(value) && trues.add(account)…