What are the differences between Iterator and Spliterator in Java 8?

Main differences between Iterator and Spliterator are as follows:

  • Spliterator can be used with Streams in Java 8. Where as, Iterator is just used with Collection.
  • Spliterator uses Internal Iteration to iterate Streams. Iterator uses External Iteration to iterate Collections.
  • Spliterator can iterate Streams in Parallel as well as Sequential manner. Iterator only iterates in Sequential manner.
  • Spliterator can traverse elements individually as well as in bulk. Iterator only iterates elements individually.
Read the full book at www.amazon.com
Posted in Java 8, Java 8 Interview Questions

Leave a Reply

Your email address will not be published. Required fields are marked *

*