The Java Iterator interface represents an object capable of iterating through a collection of Java objects, one object at a time. The Iterator interface is one of the oldest mechanisms in Java for iterating collections of objects (although not the oldest — Enumerator predated Iterator).
Moreover, an iterator differs from the enumerations in two ways:
1. Iterator permits the caller to remove the given elements from the specified collection during the iteration of the elements.
2. Method names have been enhanced.
The list is given as : [Welcome, to, our, website] Welcome to our website After the remove() method is called : [Welcome, to, our]
Like Iterator and ListIterator, Spliterator is a Java Iterator, which is used to iterate elements one-by-one from a List implemented object.
The main functionalities of Spliterator are:
- Splitting the source data
- Processing the source data
The Interface Spliterator is included in JDK 8 for taking the advantages of parallelism in addition to sequential traversal. It is designed as a parallel analogue of an iterator.
Estimate size: 5 Exact size: 5 Boolean Result: true Elements of ArrayList : 101 201 301 401 501 Output from splitr2: 101 201 Output from splitr1: 301 401 501
Difference between Iterator and Spliterator in java :
|Introduced in Java 1.2||Introduced in Java 1.8|
|Iterator only iterates elements individually||Spliterator traverse elements individually as well as in bulk|
|It is an iterator for whole collection API||It is an iterator for both Collection and Stream API, except Map implementation classes|
|It uses external iteration||It uses internal iteration.|
|It is a Universal iterator||It is Not a Universal iterator|
|It does not support parallel programming||It supports parallel programming by splitting the given element set so that each set can be processed individually.|
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Java Program to Convert Iterator to Spliterator
- Java.util Interface Spliterator in Java8
- Java 8 | LinkedBlockingQueue spliterator() method with Examples
- ArrayBlockingQueue spliterator() method in Java
- PriorityBlockingQueue spliterator() method in Java
- LinkedTransferQueue spliterator() method in Java
- ArrayList spliterator() method in Java
- LinkedBlockingDeque spliterator() method in Java
- LinkedList spliterator() method in Java
- HashSet spliterator() method in Java
- ArrayDeque spliterator() method in Java
- ConcurrentSkipListSet spliterator() method in Java
- PriorityQueue spliterator() method in Java
- ConcurrentLinkedQueue spliterator() method in Java
- CopyOnWriteArrayList spliterator() method in Java
- CopyOnWriteArraySet spliterator() method in Java
- ConcurrentLinkedDeque Spliterator() method in Java with Examples
- Difference between an Iterator and ListIterator in Java
- Difference between Iterator and Enumeration in Java with Examples
- Java | Implementing Iterator and Iterable Interface
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.