TreeSet spliterator() in Java

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

Syntax:

Spliterator<K> java.util.TreeSet.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.TreeSet;

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

        TreeSet<String> treeSet = new TreeSet<String>();

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

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

    }
}

Output:

java.util.TreeMap$KeySpliterator@41a4555e


No comments:

Post a Comment