Vector spliterator() in Java

spliterator(): This method is available in java.util.Vector class of Java.

Syntax:

Spliterator<K> java.util.Vector.spliterator()

This method creates a late-binding and fail-fast Spliterator over the elements in this list.

Parameters: NA

Returns: a Spliterator over the elements in this list.

Exceptions: NA

Approach

Java

import java.util.Spliterator;
import java.util.Vector;

public class Vectorspliterator {
    public static void main(String[] args) {

        Vector<String> vector = new Vector<>();

        vector.add("Hello");
        vector.add("Java");
        vector.add("C++");
        vector.add("Program");

        Spliterator<String> spliterator =
vector.spliterator();
        spliterator.forEachRemaining((n ->
System.out.print(n + " ")));

    }
}

Output:

Hello Java C++ Program 


No comments:

Post a Comment