86
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
Output:
Vijay Mohan Ravi Ajay
Example 2
Output:
Output: 98 Output: 67 Output: 24 Output: 45
Example 3
Output:
Rahul Mohan Karan
Next TopicHashSet remove() Method