SortedSet iterator() method in Java with Examples Last Updated : 30 Sep, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The java.util.SortedSet.iterator() method is used to return an iterator of the same elements as the set. The elements are returned in random order from what present in the set. Syntax: Iterator iterate_value = sortedSetInstance.iterator(); Parameters: The function does not take any parameter. Return Value: The method iterates over the elements of the set and returns the values(iterators). Note: The iterator() method in SortedSet is inherited from the Set interface in Java. Below program illustrate the java.util.Set.iterator() method: Java // Java code to illustrate iterator() import java.util.*; public class SortedSetDemo { public static void main(String args[]) { // Creating an empty Set SortedSet<String> set = new TreeSet<String>(); // Use add() method to // add elements into the Set set.add("Welcome"); set.add("To"); set.add("Geeks"); set.add("4"); set.add("Geeks"); // Displaying the Set System.out.println("SortedSet: " + set); // Creating an iterator Iterator value = set.iterator(); // Displaying the values after // iterating through the iterator System.out.println("The iterator values are: "); while (value.hasNext()) { System.out.println(value.next()); } } } Output: SortedSet: [4, Geeks, To, Welcome] The iterator values are: 4 Geeks To Welcome Reference: https://docs.oracle.com/javase/7/docs/api/java/util/Set.html#iterator() Comment More infoAdvertise with us Next Article Set iterator() method in Java with Examples G gopaldave Follow Improve Article Tags : Java Java - util package Java-Functions Java-SortedSet Practice Tags : Java Similar Reads Set iterator() method in Java with Examples The java.util.Set.iterator() method is used to return an iterator of the same elements as the set. The elements are returned in random order from what present in the set. Syntax: Iterator iterate_value = Set.iterator(); Parameters: The function does not take any parameter. Return Value: The method i 1 min read Vector iterator() method in Java with Examples iterator() method of Vector class that is present inside java.util package is used to return an iterator of the same elements as that of the Vector. The elements are returned in random order from what was present in the vector. Syntax: Iterator iterate_value = Vector.iterator(); Parameters: The func 2 min read Path iterator() method in Java with Examples The iterator() method of java.nio.file.Path used to returns an iterator of the name elements which construct this path. The first element of this iterator contains the name element that is closest to the root in the directory hierarchy, the second element is the next closest, and so on. The last ele 2 min read Stack iterator() method in Java with Example The Java.util.Stack.iterator() method is used to return an iterator of the same elements as that of the Stack. The elements are returned in random order from what was present in the stack. Syntax: Iterator iterate_value = Stack.iterator(); Parameters: The function does not take any parameter. Return 2 min read ArrayList iterator() method in Java with Examples The iterator() method of ArrayList class in Java Collection Framework is used to get an iterator over the elements in this list in proper sequence. The returned iterator is fail-fast. Syntax: Iterator iterator() Parameter: This method do not accept any parameter. Return Value: This method returns an 2 min read DelayQueue iterator() method in Java with Examples The iterator() method of DelayQueue is used to return an iterator over all the elements in the DelayQueue. These elements can be expired or unexpired.Syntax: public Iterator iterator () Parameters: This method does not accept any parameter.Returns: This method returns an iterator over elements in th 2 min read Like