Home » Java HashSet iterator() Method with Examples

Java HashSet iterator() Method with Examples

by Online Tutorials Library

Java HashSet iterator() Method

The iterator() method of Java HashSet class is used to return an iterator of the same elements as the HashSet. It return elements in random order from what present in the HashSet.

Syntax

Following is the declaration of iterator() method:

Parameter

This method does not accept any parameter.

Returns

The iterator() method returns an Iterator over the elements in this set.

Exceptions

NA

Compatibility Version

Java 1.2 and above

Example 1

Test it Now

Output:

Vijay  Mohan  Ravi  Ajay  

Example 2

Test it Now

Output:

Output: 98  Output: 67  Output: 24  Output: 45  

Example 3

Test it Now

Output:

Rahul  Mohan  Karan  

You may also like