Sort items in a Set : TreeSet « Collections Data Structure « Java
- Java
- Collections Data Structure
- TreeSet
Sort items in a Set
import java.util.Set;
import java.util.TreeSet;
public class Main {
public static void main(String[] args) {
Set<String> set = new TreeSet<String>();
set.add("Z");
set.add("A");
set.add("F");
set.add("B");
set.add("H");
set.add("X");
set.add("N");
for (String item : set) {
System.out.print(item + " ");
}
}
}
Related examples in the same category