Run ❯
Get your
own Java
server
×
Change Orientation
Change Theme, Dark/Light
Go to Spaces
import java.util.ArrayList; import java.util.Spliterator; public class Main { public static void main(String[] args) { // Make a collection ArrayList
cars = new ArrayList
(); cars.add("Volvo"); cars.add("BMW"); cars.add("Ford"); cars.add("Mazda"); // Get the spliterator and split it Spliterator
it1 = cars.spliterator(); Spliterator
it2 = it1.trySplit(); // Loop through the first spliterator System.out.println("First spliterator"); while( it1.tryAdvance( (n) -> { System.out.println(n); } ) ); // Loop through the second spliterator System.out.println("\nSecond spliterator"); while( it2.tryAdvance( (n) -> { System.out.println(n); } ) ); } }
First spliterator
Ford
Mazda
Second spliterator
Volvo
BMW