TreeSet is a sorted set(SortedSet)
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
public class Main {
public static void main(String[] argv) throws Exception {
Set<String> set = new TreeSet<String>();
set.add("b");
set.add("c");
set.add("a");
Iterator it = set.iterator();
while (it.hasNext()) {
Object element = it.next();
}
String[] array = (String[]) set.toArray(new String[set.size()]);
System.out.println(set);
}
}
Output:
[a, b, c]
Home
Java Book
Runnable examples
Java Book
Runnable examples
Collection TreeSet:
- TreeSet is a sorted set(SortedSet)
- First in a TreeSet
- Head Set from TreeSet
- Higher and lower set
- Last from a Set
- Reverse order a TreeSet
- Tail set, header set and sub set