Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to Convert Iterator to Spliterator
To convert Iterator to Spliterator, the Java code is as follows −
Example
import java.util.*;
public class Demo{
public static <T> Spliterator<T> getspiliter(Iterator<T> iterator){
return Spliterators.spliteratorUnknownSize(iterator, 0);
}
public static void main(String[] args){
Iterator<Integer> my_iter = Arrays.asList(56, 78, 99, 32, 100, 234).iterator();
Spliterator<Integer> my_spliter = getspiliter(my_iter);
System.out.println("The values in the spliterator are : ");
my_spliter.forEachRemaining(System.out::println);
}
}
Output
The values in the spliterator are : 56 78 99 32 100 234
A class named Demo contains a function named ‘getspiliter’ that returns a spliterator. In the main function, an iterator is run through a list of array values. The ‘getspliliter’ function is called on this and the array values are converted to spliterator. The same is displayed on the console.
Advertisements