Wednesday, 18 January 2017

TreeSet : PollMethod





import java.util.TreeSet;

public class PollMethod {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

       
TreeSet<Integer> ts1 = new TreeSet<>();   
       
        ts1.add(36);
        ts1.add(48);
        ts1.add(24);
        ts1.add(64);
        ts1.add(24);
        ts1.add(12);
       
        System.out.println("Full-List (Duplicate Not Allowed && Maintain Ascending Order in TreeSet) : "+ts1);
       
        System.out.println(" get first element and remove"+ts1.pollFirst());
        System.out.println("Full-List (Duplicate Not Allowed && Maintain Ascending Order in TreeSet) : "+ts1);
       
        System.out.println(" get last element and remove "+ts1.pollLast());
        System.out.println("Full-List (Duplicate Not Allowed && Maintain Ascending Order in TreeSet) : "+ts1);
    }
}

No comments:

Post a Comment