LinkedHashSet spliterator() in Java

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

Syntax:

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

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

Parameters: NA

Returns: a Spliterator over the elements in this set.

Exceptions: NA

Approach

Java

import java.util.LinkedHashSet;
import java.util.Spliterator;

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

        LinkedHashSet<String> linkedHashSet =
new LinkedHashSet<>();

        linkedHashSet.add("Hello");
        linkedHashSet.add("Java");
        Spliterator<String> spliterator =
linkedHashSet.spliterator();

        System.out.println(spliterator.toString());

    }
}

Output:

java.util.Spliterators$IteratorSpliterator@2d363fb3


No comments:

Post a Comment