Home Tutorial Java Core Hashset Example of Hashset size() method in java.

 
 

Share on Google+Share on Google+
Example of Hashset size() method in java.
Posted on: April 4, 2011 at 12:00 AM
Advertisement
Example of Hashset size() method in java.

Example of Hashset size() method in java.

The size() is a method of HashSet class. It is used to calculte the size of HashSet. The size of method is equal to total number of elements in HashSet

Code

SizeOfHashSet.java

package net.roseindia;

import java.util.HashSet;

public class SizeOfHashSet {

public static void main(String[] arg) {

HashSet obHashSet = new HashSet();

obHashSet.add(new Integer(1));

obHashSet.add(new Integer(2));

obHashSet.add(new Integer(3));

obHashSet.add(new Integer(4));

System.out.println("All Elements in HashSet : " + obHashSet);

System.out.println("Size of HashSet : " + obHashSet.size());

} }

Output :

All Elements in HashSet : [1, 2, 3, 4]

Size of HashSet : 4

Advertisement

Related Tags for Example of Hashset size() method in java.:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 4, 2011

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com