Java HashSet iterator() MethodThe 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. SyntaxFollowing is the declaration of iterator() method: ParameterThis method does not accept any parameter. ReturnsThe iterator() method returns an Iterator over the elements in this set. ExceptionsNA Compatibility VersionJava 1.2 and above Example 1Test it NowOutput: Vijay Mohan Ravi Ajay Example 2Test it NowOutput: Output: 98 Output: 67 Output: 24 Output: 45 Example 3Test it NowOutput: Rahul Mohan Karan
Next TopicHashSet remove() Method
|