remove specific element in a Java TreeSet Example

remove specific element in a Java TreeSet Example


Posted in : Java Posted on : November 24, 2010 at 5:44 PM Comments : [ 0 ]

This Java Example shows how to remove specific elements which exists in TreeSet.

remove in  Java TreeSet Example

This Java Example shows how to remove specific elements which exists in TreeSet. To remove elements exists in TreeSet We use remove() method of TreeSet class.  It removes the specified element stored in the specified object within the collection.

Example:- RemoveInTreeSet.java

package devmanuals.com;

import java.util.*;

public class RemoveInTreeSet {
	public static void main(String[] args) {

		TreeSet st = new TreeSet();

		st.add("Gyan");
		st.add("Rohit");
		st.add("Anand");
		st.add("Arunesh");
		System.out.println("The size of the tree set is :" + st.size());
		st.remove("Gyan");
		System.out.println("The size of the tree set after removing  is :"
				+ st.size());
		st.remove("Anand");
		System.out.println("The size of the tree set again removing is :"
				+ st.size());
	}
}

Output:-

The size of the tree set is :4

The size of the tree set after removing is :3

The size of the tree set again removing is :2

Download The Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics