» » » Get Size of Java TreeSet Example

1.Basic Java example program get size of treeset


  1. package com.TreeSetExamplePrograms;

  2. public Class TreeSetGetSizeDemo{ 
  3.  
  4. public static void main(String args[]) {
  5. //create TreeSet object
  6.  
  7.  TreeSet<String> treeSet = new TreeSet<String>();
  8.  
  9.    //add elements to TreeSet
  10.     treeSet.add("I");
  11.     treeSet.add("N");
  12.     treeSet.add("S");
  13.     treeSet.add("T");
  14.     treeSet.add("A");
  15.     treeSet.add("N");
  16.     treeSet.add("C");
  17.     treeSet.add("E");
  18.           
  19.     treeSet.add("O");
  20.     treeSet.add("F");
  21.           
  22.     System.out.println(treeSet);
  23.           
  24.    System.out.println("Size of TreeSet  : " + treeSet.size());           
  25.     //remove one element from TreeSet using remove method
  26.  
  27.      treeSet.remove("A");
  28.  
  29.  System.out.println("Size of TreeSet after removal of element A : " + treeSet.size()); 
  30.  System.out.println(treeSet);

  31. }
  32. }



Output:


  1. [A, C, E, F, I, N, O, S, T]
  2. Size of TreeSet  : 9
  3. Size of TreeSet after removal of element A : 8
  4. [C, E, F, I, N, O, S, T]

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu