LinkedHashSet remove(Object) in Java

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

Syntax:

boolean java.util.HashSet.remove(Object o)

This method takes one argument. This method removes the specified element from this set if it is present. Returns true if this set contained the element.

Parameters: One parameter is required for this method.

o: object to be removed from this set, if present.

Returns: true if the set contained the specified element.

Exceptions: NA

Approach

Java

import java.util.LinkedHashSet;

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

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

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

        Object o = "Hello";

        System.out.println(linkedHashSet.remove(o));

    }
}

Output:

true


No comments:

Post a Comment