Ben Chuanlong Du's Blog

It is never too late to learn.

Set in Java

Reference

In [2]:
import java.util.Iterator;
import java.util.SortedSet;
import java.util.TreeSet;

SortedSet<Integer> set = new TreeSet<Integer>();
set.add(8);
set.add(3);
set.add(20);
set.remove(8);
set.remove(9);
set.add(20);
Iterator<Integer> it = set.iterator();
for(;it.hasNext();){
    System.out.println(it.next()+"\n");
}
System.out.println(set);
3

20

[3, 20]
Out[2]:
null
In [ ]:

Comments