Javatpoint Logo
Javatpoint Logo

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





Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA