package devmanuals.com; import java.util.*; public class ItrateThroughElement { public static void main(String[] args) { TreeSet st = new TreeSet(); st.add("Gyan"); st.add("Rohit"); st.add("Anand"); st.add("Arunesh"); Iterator itr = st.iterator(); System.out.println("The element of the TreeSet is :"); while (itr.hasNext()) { String str = (String) itr.next(); System.out.println("Name :" + str); } } }