Have a question regarding .filter (or any other non-terminal) methods in Stream API chain (code in the block below is just for example):
var s1 = Stream.of(1,2,3,4,5,6,7,8,9);
var intemidiate1 = s1.filter(i -> i % 2 == 0);
var intemidiate2 = intemidiate1.filter(i -> i < 10);
var intemidiate3 = intemidiate2.filter(i -> i < 1);
var res = intemidiate3.toList();
By hashcodes of each non-terminal operation I clearly see that Stream API creates new object of Stream each time, so does it makes sense to merge filter methods as much as possible (1 instead of ten) and give up with readability in favor of memory consumption/ performance ?
Thanks everyone
Tried to google this topic but not much info on that