Stav Alfi Stav Alfi - 10 months ago 40
Java Question

Which collection - each operation's spliterator is iterating over?

I'm trying to understand what exactly each operation's spliterator is iterating over. Please correct me if I'm wrong: (I'm most likely wrong)


  1. Each stream have
    .spliterator()
    method.

  2. Each intermediate operation can change the spliterator characteristics.



My questions:


  1. Does each intermediate operation uses and changes characteristicts in the same spliterator - the "source spliterator"?

  2. If we are using
    filter
    operation then some elements can be ommited. From which collection exactly those elements are ommited?


Answer Source
  1. Yes - it is the same spliterator. Only a single spliterator is created from the source of the Stream (there could be many Spliterators in case of parallel processing).

  2. It is the result Collection (the one from the terminal operation - which might not be a collection at all - sum, count, etc) that the elements are omitted from.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download