LinkedHashSet add() method in Java with Examples Last Updated : 30 Sep, 2019 Comments Improve Suggest changes Like Article Like Report 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_Set.add(Object element) Parameters: The parameter element is of the type LinkedHashSet and refers to the element to be added to the Set. Return Value: The function returns True if the element is not present in the LinkedHashSet otherwise False if the element is already present in the LinkedHashSet. Below program illustrate the Java.util.LinkedHashSet.add() method: Java // Java code to illustrate add() import java.io.*; import java.util.LinkedHashSet; public class LinkedHashSetDemo { public static void main(String args[]) { // Creating an empty LinkedHashSet LinkedHashSet<String> set = new LinkedHashSet<String>(); // Use add() method to add elements into the Set set.add("Welcome"); set.add("To"); set.add("Geeks"); set.add("4"); set.add("Geeks"); // Displaying the LinkedHashSet System.out.println("LinkedHashSet: " + set); } } Output: LinkedHashSet: [Welcome, To, Geeks, 4] Comment More infoAdvertise with us Next Article LinkedHashSet add() 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 clone() Method in Java with Examples 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. Retu 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 contains() Method in Java with Examples In Java, LinkedHashSet class contains methods known as contains() which is used to return true if this set contains the specified element otherwise false. Syntax: public boolean contains(Object o) Parameters: Element o as a parameter whose presence in this set is to be tested. Return Type: A boolean 2 min read List add() Method in Java with Examples The List add() method adds (appends) an element to a list. It can be used for both ArrayList and LinkedList. Example of List add() Method: Java // Java program to demonstrate // ArrayList usage import java.io.*; import java.util.ArrayList; import java.util.List; class GFG { public static void main ( 3 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 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 List addAll() Method in Java with Examples This method appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator. Syntax: boolean addAll(Collection c) Parameters: This function has a single parameter, i.e, Collection c, whose elements are to be 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 Like