I have the code below and I was hoping that finalList would get populated with the result of the filter operation of the inner stream, but it does not print anything.
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MainClass {
public static void main(String[] args) {
ArrayList<String> finalList = new ArrayList<>();
ArrayList<String> l = new ArrayList<>();
l.add("c");
l.add("e");
ArrayList<String> l1 = new ArrayList<>();
l1.add("a");
l1.add("b");
Map<String, Integer> map1 = new HashMap<>();
map1.put("a-c", 1);
map1.put("b-d", 2);
l1.stream()
.map(c-> {
System.out.println("inside map" + c);
l.stream().filter(s ->
map1.containsKey(c+"-"+s)).forEach(f-> {
System.out.println("f value is" + f);
finalList.add(f);
});
return null;
});
System.out.println("Final List is:" + finalList);
}
}
I see none of the sysouts within the map method. Please help me understand why this is not executing any code?
The output I get is:
Final List is:[]