Java stream operation invocations









up vote
14
down vote

favorite
1












Can anyone point to a official Java documentation which describes how many times Stream will invoke each "non-interfering and stateless" intermediate operation for each element.



For example:



Arrays.asList("1", "2", "3", "4").stream()
.filter(s -> check(s))
.forEach(s -> System.out.println(s));

public boolean check(Object o)
return true;



The above currently will invoke check method 4 times.



Is it possible that in the current or future versions of JDKs the check method gets executed more or less times than the number of elements in the stream created from List or any other standard Java API?










share|improve this question



















  • 4




    Is there some motive behind this question? Like, you want to add unit test like verify(times(4)).check(anyBool) such that it doesn't fail in future?
    – Aayush Kumar Singha
    Nov 9 at 23:35






  • 1




    I do not see a reason why that stream would ever return more than 4 values?
    – Mark
    Nov 9 at 23:37










  • The motive is that if check also does important processing for each element then I want to be sure that it does only once for each element in the stream.
    – tsolakp
    Nov 9 at 23:40






  • 5




    The filter predicate is supposed to be stateless.
    – Radiodef
    Nov 10 at 0:01






  • 1




    @chrylis. I don't think it will make any difference.
    – tsolakp
    Nov 10 at 0:55














up vote
14
down vote

favorite
1












Can anyone point to a official Java documentation which describes how many times Stream will invoke each "non-interfering and stateless" intermediate operation for each element.



For example:



Arrays.asList("1", "2", "3", "4").stream()
.filter(s -> check(s))
.forEach(s -> System.out.println(s));

public boolean check(Object o)
return true;



The above currently will invoke check method 4 times.



Is it possible that in the current or future versions of JDKs the check method gets executed more or less times than the number of elements in the stream created from List or any other standard Java API?










share|improve this question



















  • 4




    Is there some motive behind this question? Like, you want to add unit test like verify(times(4)).check(anyBool) such that it doesn't fail in future?
    – Aayush Kumar Singha
    Nov 9 at 23:35






  • 1




    I do not see a reason why that stream would ever return more than 4 values?
    – Mark
    Nov 9 at 23:37










  • The motive is that if check also does important processing for each element then I want to be sure that it does only once for each element in the stream.
    – tsolakp
    Nov 9 at 23:40






  • 5




    The filter predicate is supposed to be stateless.
    – Radiodef
    Nov 10 at 0:01






  • 1




    @chrylis. I don't think it will make any difference.
    – tsolakp
    Nov 10 at 0:55












up vote
14
down vote

favorite
1









up vote
14
down vote

favorite
1






1





Can anyone point to a official Java documentation which describes how many times Stream will invoke each "non-interfering and stateless" intermediate operation for each element.



For example:



Arrays.asList("1", "2", "3", "4").stream()
.filter(s -> check(s))
.forEach(s -> System.out.println(s));

public boolean check(Object o)
return true;



The above currently will invoke check method 4 times.



Is it possible that in the current or future versions of JDKs the check method gets executed more or less times than the number of elements in the stream created from List or any other standard Java API?










share|improve this question















Can anyone point to a official Java documentation which describes how many times Stream will invoke each "non-interfering and stateless" intermediate operation for each element.



For example:



Arrays.asList("1", "2", "3", "4").stream()
.filter(s -> check(s))
.forEach(s -> System.out.println(s));

public boolean check(Object o)
return true;



The above currently will invoke check method 4 times.



Is it possible that in the current or future versions of JDKs the check method gets executed more or less times than the number of elements in the stream created from List or any other standard Java API?







java java-8 java-stream






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 15:32









Mani Grover

125215




125215










asked Nov 9 at 23:32









tsolakp

4,46611219




4,46611219







  • 4




    Is there some motive behind this question? Like, you want to add unit test like verify(times(4)).check(anyBool) such that it doesn't fail in future?
    – Aayush Kumar Singha
    Nov 9 at 23:35






  • 1




    I do not see a reason why that stream would ever return more than 4 values?
    – Mark
    Nov 9 at 23:37










  • The motive is that if check also does important processing for each element then I want to be sure that it does only once for each element in the stream.
    – tsolakp
    Nov 9 at 23:40






  • 5




    The filter predicate is supposed to be stateless.
    – Radiodef
    Nov 10 at 0:01






  • 1




    @chrylis. I don't think it will make any difference.
    – tsolakp
    Nov 10 at 0:55












  • 4




    Is there some motive behind this question? Like, you want to add unit test like verify(times(4)).check(anyBool) such that it doesn't fail in future?
    – Aayush Kumar Singha
    Nov 9 at 23:35






  • 1




    I do not see a reason why that stream would ever return more than 4 values?
    – Mark
    Nov 9 at 23:37










  • The motive is that if check also does important processing for each element then I want to be sure that it does only once for each element in the stream.
    – tsolakp
    Nov 9 at 23:40






  • 5




    The filter predicate is supposed to be stateless.
    – Radiodef
    Nov 10 at 0:01






  • 1




    @chrylis. I don't think it will make any difference.
    – tsolakp
    Nov 10 at 0:55







4




4




Is there some motive behind this question? Like, you want to add unit test like verify(times(4)).check(anyBool) such that it doesn't fail in future?
– Aayush Kumar Singha
Nov 9 at 23:35




Is there some motive behind this question? Like, you want to add unit test like verify(times(4)).check(anyBool) such that it doesn't fail in future?
– Aayush Kumar Singha
Nov 9 at 23:35




1




1




I do not see a reason why that stream would ever return more than 4 values?
– Mark
Nov 9 at 23:37




I do not see a reason why that stream would ever return more than 4 values?
– Mark
Nov 9 at 23:37












The motive is that if check also does important processing for each element then I want to be sure that it does only once for each element in the stream.
– tsolakp
Nov 9 at 23:40




The motive is that if check also does important processing for each element then I want to be sure that it does only once for each element in the stream.
– tsolakp
Nov 9 at 23:40




5




5




The filter predicate is supposed to be stateless.
– Radiodef
Nov 10 at 0:01




The filter predicate is supposed to be stateless.
– Radiodef
Nov 10 at 0:01




1




1




@chrylis. I don't think it will make any difference.
– tsolakp
Nov 10 at 0:55




@chrylis. I don't think it will make any difference.
– tsolakp
Nov 10 at 0:55












2 Answers
2






active

oldest

votes

















up vote
15
down vote



accepted










This does not have to do with the source of the stream, but rather the terminal operation and optimization done in the stream implementation itself. For example:



Stream.of(1,2,3,4)
.map(x -> x + 1)
.count();


Since java-9, map will not get executed a single time.



Or:



 someTreeSet.stream()
.sorted()
.findFirst();


sorted might not get executed at all, since the source is a TreeSet and getting the first element is trivial, but if this is implemented inside stream API or not, is a different question.



So the real answer here - it depends, but I can't imagine one operation that would get executed more that the numbers of elements in the source.






share|improve this answer
















  • 2




    "but I can't imagine one operation that would get executed more that the numbers of elements in the source" - Well, if you specify a Comparator for sorting, its compare will definitely be invoked more times than the number of elements, but that's just nitpicking. +1
    – Fureeish
    Nov 9 at 23:46






  • 1




    @Fureeish no no, very good nitpick, indeed you are right; but it seems sorted is the only one that could do that. distinct does not for example
    – Eugene
    Nov 9 at 23:53






  • 1




    Some time ago I asked this question about jdk8 flatMap (also see this related question). In short, in jdk8&9 flatMap is not completely lazy and elements can be visited more than once, while in jdk10 this behavior has been fixed.
    – Federico Peralta Schaffner
    Nov 10 at 0:13







  • 1




    @FedericoPeraltaSchaffner as said earlier I can write it as Stream.of(1, 1) .flatMap(x -> Stream.of(x, x)) .forEach(System.out::println); does it mean that it gets visited more than once?
    – Eugene
    Nov 10 at 0:34






  • 2




    4 times according to my own maths ;) I get your point, I was thinking about tricky use cases with flatMap, followed by filter. In such hypothetical cases, maybe reality is counterintuituve. Let me try to find an example...
    – Federico Peralta Schaffner
    Nov 10 at 0:43

















up vote
3
down vote













From the documentation:




Laziness-seeking. Many stream operations, such as filtering, mapping, or duplicate removal, can be implemented lazily, exposing opportunities for optimization. For example, "find the first String with three consecutive vowels" need not examine all the input strings. Stream operations are divided into intermediate (Stream-producing) operations and terminal (value- or side-effect-producing) operations. Intermediate operations are always lazy.




By that virtue, because filter is an intermediate operation which creates a new Stream as part of its operation, due to its laziness, it will only ever invoke the filter predicate once per element as part of its rebuilding of the stream.



The only way that your method would possibly have a different number of invocations against it in the stream is if the stream were somehow mutated between states, which given the fact that nothing in a stream actually runs until the terminal operation, would only realistically be possible due to a bug upstream.






share|improve this answer




















  • So what does "Laziness" mean in Java streams? To me it means that the actual invocation of intermediate operation will happen after invocation of terminal operation. But it does not guarantee that intermediate operation will be invoked only once per element (or not at all depending on terminal operation).
    – tsolakp
    Nov 10 at 0:32










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234586%2fjava-stream-operation-invocations%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
15
down vote



accepted










This does not have to do with the source of the stream, but rather the terminal operation and optimization done in the stream implementation itself. For example:



Stream.of(1,2,3,4)
.map(x -> x + 1)
.count();


Since java-9, map will not get executed a single time.



Or:



 someTreeSet.stream()
.sorted()
.findFirst();


sorted might not get executed at all, since the source is a TreeSet and getting the first element is trivial, but if this is implemented inside stream API or not, is a different question.



So the real answer here - it depends, but I can't imagine one operation that would get executed more that the numbers of elements in the source.






share|improve this answer
















  • 2




    "but I can't imagine one operation that would get executed more that the numbers of elements in the source" - Well, if you specify a Comparator for sorting, its compare will definitely be invoked more times than the number of elements, but that's just nitpicking. +1
    – Fureeish
    Nov 9 at 23:46






  • 1




    @Fureeish no no, very good nitpick, indeed you are right; but it seems sorted is the only one that could do that. distinct does not for example
    – Eugene
    Nov 9 at 23:53






  • 1




    Some time ago I asked this question about jdk8 flatMap (also see this related question). In short, in jdk8&9 flatMap is not completely lazy and elements can be visited more than once, while in jdk10 this behavior has been fixed.
    – Federico Peralta Schaffner
    Nov 10 at 0:13







  • 1




    @FedericoPeraltaSchaffner as said earlier I can write it as Stream.of(1, 1) .flatMap(x -> Stream.of(x, x)) .forEach(System.out::println); does it mean that it gets visited more than once?
    – Eugene
    Nov 10 at 0:34






  • 2




    4 times according to my own maths ;) I get your point, I was thinking about tricky use cases with flatMap, followed by filter. In such hypothetical cases, maybe reality is counterintuituve. Let me try to find an example...
    – Federico Peralta Schaffner
    Nov 10 at 0:43














up vote
15
down vote



accepted










This does not have to do with the source of the stream, but rather the terminal operation and optimization done in the stream implementation itself. For example:



Stream.of(1,2,3,4)
.map(x -> x + 1)
.count();


Since java-9, map will not get executed a single time.



Or:



 someTreeSet.stream()
.sorted()
.findFirst();


sorted might not get executed at all, since the source is a TreeSet and getting the first element is trivial, but if this is implemented inside stream API or not, is a different question.



So the real answer here - it depends, but I can't imagine one operation that would get executed more that the numbers of elements in the source.






share|improve this answer
















  • 2




    "but I can't imagine one operation that would get executed more that the numbers of elements in the source" - Well, if you specify a Comparator for sorting, its compare will definitely be invoked more times than the number of elements, but that's just nitpicking. +1
    – Fureeish
    Nov 9 at 23:46






  • 1




    @Fureeish no no, very good nitpick, indeed you are right; but it seems sorted is the only one that could do that. distinct does not for example
    – Eugene
    Nov 9 at 23:53






  • 1




    Some time ago I asked this question about jdk8 flatMap (also see this related question). In short, in jdk8&9 flatMap is not completely lazy and elements can be visited more than once, while in jdk10 this behavior has been fixed.
    – Federico Peralta Schaffner
    Nov 10 at 0:13







  • 1




    @FedericoPeraltaSchaffner as said earlier I can write it as Stream.of(1, 1) .flatMap(x -> Stream.of(x, x)) .forEach(System.out::println); does it mean that it gets visited more than once?
    – Eugene
    Nov 10 at 0:34






  • 2




    4 times according to my own maths ;) I get your point, I was thinking about tricky use cases with flatMap, followed by filter. In such hypothetical cases, maybe reality is counterintuituve. Let me try to find an example...
    – Federico Peralta Schaffner
    Nov 10 at 0:43












up vote
15
down vote



accepted







up vote
15
down vote



accepted






This does not have to do with the source of the stream, but rather the terminal operation and optimization done in the stream implementation itself. For example:



Stream.of(1,2,3,4)
.map(x -> x + 1)
.count();


Since java-9, map will not get executed a single time.



Or:



 someTreeSet.stream()
.sorted()
.findFirst();


sorted might not get executed at all, since the source is a TreeSet and getting the first element is trivial, but if this is implemented inside stream API or not, is a different question.



So the real answer here - it depends, but I can't imagine one operation that would get executed more that the numbers of elements in the source.






share|improve this answer












This does not have to do with the source of the stream, but rather the terminal operation and optimization done in the stream implementation itself. For example:



Stream.of(1,2,3,4)
.map(x -> x + 1)
.count();


Since java-9, map will not get executed a single time.



Or:



 someTreeSet.stream()
.sorted()
.findFirst();


sorted might not get executed at all, since the source is a TreeSet and getting the first element is trivial, but if this is implemented inside stream API or not, is a different question.



So the real answer here - it depends, but I can't imagine one operation that would get executed more that the numbers of elements in the source.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 9 at 23:40









Eugene

66.6k996159




66.6k996159







  • 2




    "but I can't imagine one operation that would get executed more that the numbers of elements in the source" - Well, if you specify a Comparator for sorting, its compare will definitely be invoked more times than the number of elements, but that's just nitpicking. +1
    – Fureeish
    Nov 9 at 23:46






  • 1




    @Fureeish no no, very good nitpick, indeed you are right; but it seems sorted is the only one that could do that. distinct does not for example
    – Eugene
    Nov 9 at 23:53






  • 1




    Some time ago I asked this question about jdk8 flatMap (also see this related question). In short, in jdk8&9 flatMap is not completely lazy and elements can be visited more than once, while in jdk10 this behavior has been fixed.
    – Federico Peralta Schaffner
    Nov 10 at 0:13







  • 1




    @FedericoPeraltaSchaffner as said earlier I can write it as Stream.of(1, 1) .flatMap(x -> Stream.of(x, x)) .forEach(System.out::println); does it mean that it gets visited more than once?
    – Eugene
    Nov 10 at 0:34






  • 2




    4 times according to my own maths ;) I get your point, I was thinking about tricky use cases with flatMap, followed by filter. In such hypothetical cases, maybe reality is counterintuituve. Let me try to find an example...
    – Federico Peralta Schaffner
    Nov 10 at 0:43












  • 2




    "but I can't imagine one operation that would get executed more that the numbers of elements in the source" - Well, if you specify a Comparator for sorting, its compare will definitely be invoked more times than the number of elements, but that's just nitpicking. +1
    – Fureeish
    Nov 9 at 23:46






  • 1




    @Fureeish no no, very good nitpick, indeed you are right; but it seems sorted is the only one that could do that. distinct does not for example
    – Eugene
    Nov 9 at 23:53






  • 1




    Some time ago I asked this question about jdk8 flatMap (also see this related question). In short, in jdk8&9 flatMap is not completely lazy and elements can be visited more than once, while in jdk10 this behavior has been fixed.
    – Federico Peralta Schaffner
    Nov 10 at 0:13







  • 1




    @FedericoPeraltaSchaffner as said earlier I can write it as Stream.of(1, 1) .flatMap(x -> Stream.of(x, x)) .forEach(System.out::println); does it mean that it gets visited more than once?
    – Eugene
    Nov 10 at 0:34






  • 2




    4 times according to my own maths ;) I get your point, I was thinking about tricky use cases with flatMap, followed by filter. In such hypothetical cases, maybe reality is counterintuituve. Let me try to find an example...
    – Federico Peralta Schaffner
    Nov 10 at 0:43







2




2




"but I can't imagine one operation that would get executed more that the numbers of elements in the source" - Well, if you specify a Comparator for sorting, its compare will definitely be invoked more times than the number of elements, but that's just nitpicking. +1
– Fureeish
Nov 9 at 23:46




"but I can't imagine one operation that would get executed more that the numbers of elements in the source" - Well, if you specify a Comparator for sorting, its compare will definitely be invoked more times than the number of elements, but that's just nitpicking. +1
– Fureeish
Nov 9 at 23:46




1




1




@Fureeish no no, very good nitpick, indeed you are right; but it seems sorted is the only one that could do that. distinct does not for example
– Eugene
Nov 9 at 23:53




@Fureeish no no, very good nitpick, indeed you are right; but it seems sorted is the only one that could do that. distinct does not for example
– Eugene
Nov 9 at 23:53




1




1




Some time ago I asked this question about jdk8 flatMap (also see this related question). In short, in jdk8&9 flatMap is not completely lazy and elements can be visited more than once, while in jdk10 this behavior has been fixed.
– Federico Peralta Schaffner
Nov 10 at 0:13





Some time ago I asked this question about jdk8 flatMap (also see this related question). In short, in jdk8&9 flatMap is not completely lazy and elements can be visited more than once, while in jdk10 this behavior has been fixed.
– Federico Peralta Schaffner
Nov 10 at 0:13





1




1




@FedericoPeraltaSchaffner as said earlier I can write it as Stream.of(1, 1) .flatMap(x -> Stream.of(x, x)) .forEach(System.out::println); does it mean that it gets visited more than once?
– Eugene
Nov 10 at 0:34




@FedericoPeraltaSchaffner as said earlier I can write it as Stream.of(1, 1) .flatMap(x -> Stream.of(x, x)) .forEach(System.out::println); does it mean that it gets visited more than once?
– Eugene
Nov 10 at 0:34




2




2




4 times according to my own maths ;) I get your point, I was thinking about tricky use cases with flatMap, followed by filter. In such hypothetical cases, maybe reality is counterintuituve. Let me try to find an example...
– Federico Peralta Schaffner
Nov 10 at 0:43




4 times according to my own maths ;) I get your point, I was thinking about tricky use cases with flatMap, followed by filter. In such hypothetical cases, maybe reality is counterintuituve. Let me try to find an example...
– Federico Peralta Schaffner
Nov 10 at 0:43












up vote
3
down vote













From the documentation:




Laziness-seeking. Many stream operations, such as filtering, mapping, or duplicate removal, can be implemented lazily, exposing opportunities for optimization. For example, "find the first String with three consecutive vowels" need not examine all the input strings. Stream operations are divided into intermediate (Stream-producing) operations and terminal (value- or side-effect-producing) operations. Intermediate operations are always lazy.




By that virtue, because filter is an intermediate operation which creates a new Stream as part of its operation, due to its laziness, it will only ever invoke the filter predicate once per element as part of its rebuilding of the stream.



The only way that your method would possibly have a different number of invocations against it in the stream is if the stream were somehow mutated between states, which given the fact that nothing in a stream actually runs until the terminal operation, would only realistically be possible due to a bug upstream.






share|improve this answer




















  • So what does "Laziness" mean in Java streams? To me it means that the actual invocation of intermediate operation will happen after invocation of terminal operation. But it does not guarantee that intermediate operation will be invoked only once per element (or not at all depending on terminal operation).
    – tsolakp
    Nov 10 at 0:32














up vote
3
down vote













From the documentation:




Laziness-seeking. Many stream operations, such as filtering, mapping, or duplicate removal, can be implemented lazily, exposing opportunities for optimization. For example, "find the first String with three consecutive vowels" need not examine all the input strings. Stream operations are divided into intermediate (Stream-producing) operations and terminal (value- or side-effect-producing) operations. Intermediate operations are always lazy.




By that virtue, because filter is an intermediate operation which creates a new Stream as part of its operation, due to its laziness, it will only ever invoke the filter predicate once per element as part of its rebuilding of the stream.



The only way that your method would possibly have a different number of invocations against it in the stream is if the stream were somehow mutated between states, which given the fact that nothing in a stream actually runs until the terminal operation, would only realistically be possible due to a bug upstream.






share|improve this answer




















  • So what does "Laziness" mean in Java streams? To me it means that the actual invocation of intermediate operation will happen after invocation of terminal operation. But it does not guarantee that intermediate operation will be invoked only once per element (or not at all depending on terminal operation).
    – tsolakp
    Nov 10 at 0:32












up vote
3
down vote










up vote
3
down vote









From the documentation:




Laziness-seeking. Many stream operations, such as filtering, mapping, or duplicate removal, can be implemented lazily, exposing opportunities for optimization. For example, "find the first String with three consecutive vowels" need not examine all the input strings. Stream operations are divided into intermediate (Stream-producing) operations and terminal (value- or side-effect-producing) operations. Intermediate operations are always lazy.




By that virtue, because filter is an intermediate operation which creates a new Stream as part of its operation, due to its laziness, it will only ever invoke the filter predicate once per element as part of its rebuilding of the stream.



The only way that your method would possibly have a different number of invocations against it in the stream is if the stream were somehow mutated between states, which given the fact that nothing in a stream actually runs until the terminal operation, would only realistically be possible due to a bug upstream.






share|improve this answer












From the documentation:




Laziness-seeking. Many stream operations, such as filtering, mapping, or duplicate removal, can be implemented lazily, exposing opportunities for optimization. For example, "find the first String with three consecutive vowels" need not examine all the input strings. Stream operations are divided into intermediate (Stream-producing) operations and terminal (value- or side-effect-producing) operations. Intermediate operations are always lazy.




By that virtue, because filter is an intermediate operation which creates a new Stream as part of its operation, due to its laziness, it will only ever invoke the filter predicate once per element as part of its rebuilding of the stream.



The only way that your method would possibly have a different number of invocations against it in the stream is if the stream were somehow mutated between states, which given the fact that nothing in a stream actually runs until the terminal operation, would only realistically be possible due to a bug upstream.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 9 at 23:48









Makoto

79.3k15122164




79.3k15122164











  • So what does "Laziness" mean in Java streams? To me it means that the actual invocation of intermediate operation will happen after invocation of terminal operation. But it does not guarantee that intermediate operation will be invoked only once per element (or not at all depending on terminal operation).
    – tsolakp
    Nov 10 at 0:32
















  • So what does "Laziness" mean in Java streams? To me it means that the actual invocation of intermediate operation will happen after invocation of terminal operation. But it does not guarantee that intermediate operation will be invoked only once per element (or not at all depending on terminal operation).
    – tsolakp
    Nov 10 at 0:32















So what does "Laziness" mean in Java streams? To me it means that the actual invocation of intermediate operation will happen after invocation of terminal operation. But it does not guarantee that intermediate operation will be invoked only once per element (or not at all depending on terminal operation).
– tsolakp
Nov 10 at 0:32




So what does "Laziness" mean in Java streams? To me it means that the actual invocation of intermediate operation will happen after invocation of terminal operation. But it does not guarantee that intermediate operation will be invoked only once per element (or not at all depending on terminal operation).
– tsolakp
Nov 10 at 0:32

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234586%2fjava-stream-operation-invocations%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo