Java – How to get size of Set

Size of Set can be find by size() method. In size method, it will return value in integer.

Example of finding size in Set in Java

Set<String> s=new TreeSet<String>();

s.add("b");
s.add("a");
s.add("d");
s.add("c");

int sizeOfSet=s.size();

System.out.println("Size of Set :"+sizeOfSet);

Output

Size of Set :4

Tags:

Bookmark  

 

Leave a Reply

Security Code:

 

  Random Post