Java Program to Traverse the Vector Collection Using Spliterator() Method

You are currently viewing Java Program to Traverse the Vector Collection Using Spliterator() Method

Java program to traverse the Vector collection using spliterator() method

// Java program to traverse the Vector collection 
// using Spliterator

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Vector < Integer > vec = new Vector < Integer > ();

    vec.add(10);
    vec.add(20);
    vec.add(30);
    vec.add(20);
    vec.add(12);

    Spliterator < Integer > items = vec.spliterator();

    System.out.println("Vector Elements:");
    items.forEachRemaining((n) -> System.out.println(n));
  }
}

Output

Vector Elements:
10
20
30
20
12

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply