LinkedHashSet clone() Method in Java with Examples Last Updated : 18 Nov, 2021 Comments Improve Suggest changes Like Article Like Report The clone() method of LinkedHashSet class is used to return a shallow copy of the mentioned hash set. It just creates a copy of the set. --> java.util Package --> LinkedHashSet Class --> clone() Method Syntax: linked_hash_set.clone() Parameters: The method does not take any parameters. Return Type: The method just returns a copy of the LinkedHashSet. Example: Java // Java Program to illustrate clone() Method // of LinkedHashSet Class // Importing required classes import java.io.*; import java.util.LinkedHashSet; // Main class public class GFG { // Main driver method public static void main(String args[]) { // Creating an empty LinkedHashSet LinkedHashSet<String> set = new LinkedHashSet<String>(); // Adding elements into the Set // using add() method set.add("Welcome"); set.add("To"); set.add("Geeks"); set.add("4"); set.add("Geeks"); // Displaying the LinkedHashSet System.out.println("LinkedHashSet: " + set); // Creating a new cloned Set LinkedHashSet cloned_set = new LinkedHashSet(); // Cloning the above Set // using clone() method cloned_set = (LinkedHashSet)set.clone(); // Displaying the new Set after Cloning System.out.println("The new set: " + cloned_set); } } Output: LinkedHashSet: [Welcome, To, Geeks, 4] The new set: [Welcome, To, Geeks, 4] Comment More infoAdvertise with us Next Article LinkedHashSet clone() Method in Java with Examples gopaldave Follow Improve Article Tags : Java Java-Functions java-LinkedHashSet Practice Tags : Java Similar Reads LinkedHashSet clear() method in Java with Examples The clear() method of java.util.LinkedHashSet class is used to remove all of the elements from this set. The set will be empty after this call returns. Syntax: public void clear() Return Value: This method does not return anything. Below are the examples to illustrate the clear() method. Example 1: 2 min read LinkedHashSet add() method in Java with Examples The add() method in Java LinkedHashSet is used to add a specific element into a LinkedHashSet. This method will add the element only if the specified element is not present in the LinkedHashSet else the function will return False if the element is already present in the LinkedHashSet. Syntax: Hash_S 1 min read LinkedHashSet equals() method in Java with Example The equals() method of java.util.LinkedHashSet class is used to compare the specified object with this set for equality. Returns true if and only if the specified object is also a set, both sets have the same size, and all corresponding pairs of elements in the two sets are equal. (Two elements e1 a 2 min read LinkedHashSet hashCode() method in Java with Example The hashCode() method of LinkedHashSet in Java is used to get the hashCode value for this instance of the LinkedHashSet. It returns an integer value which is the hashCode value for this instance of the LinkedHashSet. Syntax: public int hashCode() Parameters: This function has no parameters. Returns: 2 min read Locale clone() Method in Java with Examples The clone() Method of Locale class in Java is used to simply create a clone or copy of an existing locale. The method copies the content of one locale to another. Syntax: Sec_Locale = First_Locale.clone() Parameters: This method does not take any parameters. Return Value: This method returns a clone 2 min read LinkedHashSet toArray() method in Java with Example The toArray() method of Java LinkedHashSet is used to form an array of the same elements as that of the LinkedHashSet. Basically, it copies all the element from a LinkedHashSet to a new array. Syntax: Object[] arr = LinkedHashSet.toArray() Parameters: The method does not take any parameters. Return 2 min read LinkedHashSet retainAll() method in Java with Example The retainAll() method of java.util.LinkedHashSet class is used to retain from this set all of its elements that are contained in the specified collection. Syntax: public boolean retainAll(Collection c) Parameters: This method takes collection c as a parameter containing elements to be retained from 3 min read LinkedHashSet toArray(T[]) method in Java with Example The toArray(T[]) method method of LinkedHashSet class in Java is used to form an array of the same elements as that of the LinkedHashSet. It returns an array containing all of the elements in this LinkedHashSet in the correct order; the run-time type of the returned array is that of the specified ar 4 min read Date clone() method in Java with Examples The clone() method of Date class in Java returns the duplicate of the passed Date object. This duplicate is just a shallow copy of the given Date object.Syntax: public Object clone() Parameters: The method does not accept any parameters.Return Value: The method returns a clone of the object.Below pr 2 min read Like