Home »
Java programming language
Java LinkedHashSet spliterator() Method with Example
LinkedHashSet Class spliterator() method: Here, we are going to learn about the spliterator() method of LinkedHashSet Class with its syntax and example.
Submitted by Preeti Jain, on March 24, 2020
LinkedHashSet Class spliterator() method
- spliterator() method is available in java.util package.
- spliterator() method is used to create dynamic binding and fail-fast spliterator over the objects in this LinkedHashSet.
- spliterator() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
- spliterator() method does not throw an exception at the time of operating.
Syntax:
public void spliterator();
Parameter(s):
- It does not accept any parameter.
Return value:
The return type of the method is void, it returns nothing.
Example:
// Java program to demonstrate the example
// of int spliterator() method of LinkedHashSet
import java.util.*;
public class SpliteratorOfLinkedHashSet {
public static void main(String[] args) {
// Instantiates a LinkedHashSet object
HashSet < Integer > hs = new LinkedHashSet < Integer > ();
// By using add() method is to add
// the given object of this
// LinkedHashSet
hs.add(10);
hs.add(20);
hs.add(30);
hs.add(40);
hs.add(50);
// Display LinkedHashSet
System.out.println("LinkedHashSet: " + hs);
// By using spliterator() method
// is to display LinkedHashSet
// spliterator
// Display LinkedHashSet Spliterator
System.out.println("hs.spliterator(): " + hs.spliterator());
}
}
Output
LinkedHashSet: [10, 20, 30, 40, 50]
hs.spliterator(): java.util.Spliterators$IteratorSpliterator@6956de9