Online Java Compiler By
JavaTpoint.com
import java.util.*; public class HashSetSizeExample3 { public static void main(String[] args) { //Get the HashSet object from the method init() HashSet studentSet = init(); //Print the size of the set int size = studentSet.size(); System.out.println("Size of student database is: "+size); } private static HashSet init() { //Create HashSet object HashSet
studentSet = new HashSet<>(); //Add contents in HashSet studentSet.add("Peter"); studentSet.add("Watson"); studentSet.add("Desuja"); studentSet.add("Kevin"); return studentSet; } }
Output