Java HashSet size() MethodThe size() method of Java HashSet class is used to get the number of elements in this HashSet (its cardinality). SyntaxFollowing is the declaration of size() method: ParameterThis method does not accept any parameter. ReturnsThe size() method returns the number of elements present in the HashSet. ExceptionsNA Compatibility VersionJava 1.2 and above Example 1Test it NowOutput: HashSet: [Vijay, Mohan, Ravi, Ajay] The size of the set is: 4 Example 2Test it NowOutput: Size of HashSet is: 3 Example 3Test it NowOutput: Size of student database is: 4
Next TopicHashSet spliterator() Method
|