package devamnuals.com; import java.util.AbstractSet; import java.util.Iterator; import java.util.Set; import java.util.TreeSet; class AbsSet extends AbstractSet { Set set; public AbsSet() { set= new TreeSet(); } public boolean add(Object e) { set.add(e); System.out.println(e); return true; } public Iterator iterator() { Iterator it = set.iterator(); while(it.hasNext()) System.out.println(it.next()); return null; } public int size() { System.out.println(set.size()); return 0; } public boolean isEmpty() { System.out.println("Is set empty : "+set.isEmpty()); return true; } } public class AbstractSetDemo { public static void main(String args[]) { AbsSet aset=new AbsSet(); System.out.println("Elements of Set="); for(int i=0; i<=4;i++){ aset.add(i); } System.out.println("Display the elements of set using iterator = "); aset.iterator(); System.out.println("Size of set = "); aset.size(); aset.isEmpty(); } }