share

Saturday, 6 June 2015

How To Remove Element of Treeset


import java.util.Set;
import java.util.TreeSet;

public class RemoveElement {

    public static void main(String[] args) {
       
           Set<String> ts = new TreeSet<String>();
            ts.add("mumbai");
            ts.add("delhi");
            ts.add("kolkata");
            ts.add("chandigarh");
            ts.add("dehradun");

            // print treeset
            System.out.println(" Before Remove Tree Set is = ="+ts);
           
            /*
             * Removes the specified element from this
             *  set if it is present
             */
           
            ts.remove("delhi");
           
            System.out.println(" After Remove Tree Set is = "+ts);
       
        }
   
}





Output:



 Before Remove Tree Set is = =[chandigarh, dehradun, delhi, kolkata, mumbai]

 After Remove Tree Set is = [chandigarh, dehradun, kolkata, mumbai]


Related Posts: 


No comments:

Post a Comment