LinkedHashSet clone() in Java

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

Syntax:

Object java.util.HashSet.clone()

This method returns a shallow copy of this HashSet instance: the elements themselves are not cloned.

Parameters: NA

Returns: a shallow copy of this set.

Exceptions: NA

Approach

Java

import java.util.LinkedHashSet;

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

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

        linkedHashSet.add("Hello");

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

    }
}

Output:

[Hello]


No comments:

Post a Comment