Open In App

NavigableSet iterator() method in Java

Last Updated : 11 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report
The iterator() method of NavigableSet interface in Java is used to return an iterator over the elements in this set, in ascending order. This iterator can be then used to iterate over the elements of the set. Syntax:
Iterator<E> iterator()
Where, E is the type of elements maintained by this Set container. Parameters: This function does not accepts any parameter. Return Value: It returns an iterator over the set of elements contained in this set container. Below programs illustrate the iterator() method in Java: Program 1: NavigableSet with integer elements.
Output:
Value: 0 
Value: 1 
Value: 2 
Value: 3 
Value: 4 
Value: 5 
Value: 6
Program 2: NavigableSet with string elements.
Output:
Value: A 
Value: B 
Value: C 
Value: D 
Value: E 
Value: F 
Value: G
Reference: https://docs.oracle.com/javase/10/docs/api/java/util/NavigableSet.html#iterator()

Similar Reads