size Of Java HashSet Example

size Of Java HashSet Example


Posted in : Java Posted on : November 25, 2010 at 6:09 PM Comments : [ 0 ]

This Java Example shows how to get the number of elements exists in HashSet or size of the HashSet .

size Of Java HashSet Example

This Java Example shows how to get the number of  elements exists in HashSet or size of the HashSet . To get the number of  elements exists in HashSet We use int size() method of HashSet class.  It returns the number of elements stored in the specified object within the collection.

Example:- SizeOfHashSet.java

package devmanuals.com;

import java.util.*;

public class SizeOfHashSet {
	public static void main(String[] args) {

		HashSet hst = new HashSet();

		hst.add("Gyan");
		hst.add("Rohit");
		hst.add("Anand");
		hst.add("Arunesh");

		System.out.println("The size of the HashSet is : " + hst.size());

	}
}

Output:-

The size of the HashSet is : 4

Download The Code

Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics