size(): This method is available in java.util.LinkedHashSet class of Java.
Syntax:
int java.util.HashSet.size()
This method returns the number of elements in this set (its cardinality).
Parameters: NA
Returns: the number of elements in this set (its cardinality).
Exceptions: NA
Approach
Java
import java.util.LinkedHashSet;public class LinkedHashSetsize {public static void main(String[] args) {LinkedHashSet<String> linkedHashSet =new LinkedHashSet<>();linkedHashSet.add("Hello");linkedHashSet.add("Java");System.out.println(linkedHashSet.size());}}
Output:
2
No comments:
Post a Comment