spliterator() method

spliterator() method: The spliterator in Java method of LinkedHashSet class utilizes to creates a late-binding and fail-fast Spliterator. It returns a Spliterator of the same elements as the LinkedHashSet. It returns the object of the Spliterator.

Spliterator<E> spliterator();
import java.util.LinkedHashSet;
import java.util.Spliterator;

public class ExampleOfLinkedHashSet 
{
  public static void main(String[] args) 
  {
	LinkedHashSet<String> listOfNames = new 
        LinkedHashSet<String>();
		
	listOfNames.add("JAVA");
	listOfNames.add("GOAL");
	listOfNames.add("RAVI");
		
	Spliterator<String> splitIterator = 
        listOfNames.spliterator();
		
	splitIterator.forEachRemaining( System.out :: println);
   }
}

Output:JAVA
GOAL
RAVI

Leave a Comment