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(): [email protected]





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.