Java Program to Print HashSet Elements Using Spliterator() Method

You are currently viewing Java Program to Print HashSet Elements Using Spliterator() Method

Java program to print HashSet elements using spliterator() method

import java.util.*;

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

    nums.add(1);
    nums.add(2);
    nums.add(3);
    nums.add(4);
    nums.add(5);
    nums.add(6);

    Spliterator < Integer > splt = nums.spliterator();

    System.out.println("Set elements:");
    splt.forEachRemaining((n) -> System.out.println(n));
  }
}

Output

Set elements:
1
2
3
4
5
6

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