Code example for TreeSet

Methods: add, pollFirst, size

0
        items = new TreeSet<T>();
        this.maxSize = maxSize;
    } 
 
    public void add(T item) {
        items.add(item);
        if (items.size() > maxSize)
            items.pollFirst();
    } 
 
    public int size() { 
        return items.size();
    } 
 
    public T poll() { 
        return items.pollLast();
    } 
 
    @Override 
    public Iterator<T> iterator() {
        return items.iterator();