LinkedHashSet isEmpty() in Java

isEmpty(): This method is available in java.util.LinkedHashSet class of Java.

Syntax:

boolean java.util.HashSet.isEmpty()

This method returns true if this set contains no elements.

Parameters: NA

Returns: true if this set contains no elements.

Exceptions: NA

Approach

Java

import java.util.LinkedHashSet;

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

        LinkedHashSet<String> linkedHashSet =
new LinkedHashSet<>();

        linkedHashSet.add("Hello");
        linkedHashSet.add("Java");

        System.out.println(linkedHashSet.isEmpty());

    }
}

Output:

false


No comments:

Post a Comment