remove all element of TreeSet xample

remove all element of TreeSet xample


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

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

isEmpty and clear in  Java TreeSet Example

This Java Example shows how to remove all elements exists in TreeSet. To remove all the elements exists in TreeSet We use clear() method of TreeSet class.  It removes all the elements stored in the specified object within the collection. To check that specified TreeSet object is empty or not we use boolean isEmpty() method of the TreeSet class. This method returns true if the object is empty otherwise returns false.

Example:- RemoveElementOfTreeSet.java

package devmanuals.com;

import java.util.*;

public class RemoveElementOfTreeSet {
	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.clear();
		System.out.println("The size of the tree set after removing  is :"
				+ st.size());
		boolean bool = st.isEmpty();
		System.out.println("Is the TreeSet is empty: " + bool);

	}
}

Output:-

The size of the tree set is :4

The size of the tree set after removing is :0

Is the TreeSet is empty: true

Download The Code

Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics