java - Can Stream#limit return fewer elements than expected? -


If there are at least n elements in the stream s What are the situations where the stream can be less than n elements in the stream sLimit , if any?

  stream sLimit = s.limit (n);  

The cause of the question: In, I have read that:

Despite the appearance, border (10) Not necessarily a result of a SIZED stream with 10 elements - this can be reduced.

I think the answers to Holger and Sotiros are accurate, but because the man Have given the statement, I think I should tell myself.

I'm mainly talking about, especially SIZED attribute This is basically a "stable" notification about the stream stages, which is known at the time of pipeline setup, But before the stream actually executes. Actually, it is used to determine the current performance strategy, so it should be known before the stream is executed.

Border () Operation creates a bunuwaahi, which is its upstream splitterter, hence the boundary spliterator needs to determine which features to be refunded needed. Even if its upstream splittercutter is SIZED , then it does not know the exact size, so it must close the SIZED property.

So if you wanted to, programmer, write:

  IntStream.range (0, 100) .limit (10)  

You say must there are 10 elements in that section (and it will be.) But the resulting splitter-maker is still not SIZED . After all, the limit operator does not know the difference between the above and the:

  IntStream.range (0, 1) .limit (10)  

This is because, even if there are times when it appears that this should be done, then border

operator returns a stream of known size This does not affect the sharing strategy in turn, which affects parallel efficiency.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -