Iterate through elements of Java TreeSet : TreeSet « Collections Data Structure « Java

Iterate through elements of Java TreeSet


import java.util.Iterator;
import java.util.TreeSet;

public class Main {
  public static void main(String[] args) {
    TreeSet<Integer> tSet = new TreeSet<Integer>();

    tSet.add(new Integer("1"));
    tSet.add(new Integer("2"));
    tSet.add(new Integer("3"));

    Iterator itr = tSet.iterator();

    while (itr.hasNext()){


Related examples in the same category

1.Add values to TreeSet
2.TreeSet, SortedSet and HashSet
3.Get Synchronized Set from Java TreeSet example
4.Check if a particular value exists in Java TreeSet example
5.Copy all elements of Java TreeSet to an Object Array Example
6.Get Head Set from Java TreeSet example
7.Get lowest and highest value stored in Java TreeSet
8.Get Size of Java TreeSet
9.Get Sub Set from Java TreeSet
10.Get Tail Set from Java TreeSet
11.Remove all elements from Java TreeSet
12.Remove specified element from Java TreeSet
13.Sort items in a Set
14.Loop and remove element from a TreeSet
15.Creating a Sorted Set
16.Comparable with a sorted collection.
17.A TreeSet that ensures it never grows beyond a max size.