This Java Example shows how to get the number of elements exists in TreeSet or size of the TreeSet.
size Of Java TreeSet Example
This Java Example shows how to get the number of elements exists in TreeSet or size of the TreeSet. To get the number of elements exists in TreeSet We use int size() method of TreeSet class. It returns the number of elements stored in the specified object within the collection.
Example:- SizeOfTreeSet.java
package devmanuals.com; import java.util.*; public class SizeOfTreeSet { 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()); } }
Output:-
The size of the tree set is :4
The size of the tree set after removing is :3 |
[ 0 ] Comments