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 |
[ 0 ] Comments