Checking if Element Exists in LinkedHashSet in Java Last Updated : 11 Dec, 2020 Comments Improve Suggest changes Like Article Like Report The Java.util.LinkedHashSet.contains() method is used to check whether a specific element is present in the LinkedHashSet or not. So basically it is used to check if a Set contains any particular element. The contains a method of the LinkedHashSet class returns true if the specified element is found in the LinkedHashSet object. Example: Given List: [1, 2, 3, 4] Input : FirstSearch = 1, SecondSearch = 6 Output: True FalseSyntax: Hash_Set.contains(Object element)Return Type: If the element found in the then it returns true, else false. Parameters: The parameter element is of the type of LinkedHashSet. This is the element that needs to be tested if it is present in the set or not. Example: Java // Checking if element exists in LinkedHashSet in Java import java.util.LinkedHashSet; public class LinkedHashSetContainsExample { public static void main(String[] args) { LinkedHashSet<String> lhSetColors = new LinkedHashSet<String>(); lhSetColors.add("red"); lhSetColors.add("green"); lhSetColors.add("blue"); /* * To check if the LinkedHashSet contains the * element, use the contains method. */ // this will return true as the "red" element exists System.out.println(lhSetColors.contains("red")); // this will return true as the "white" element does // not exists System.out.println(lhSetColors.contains("white")); } } Outputtrue false Comment More infoAdvertise with us Next Article Checking if Element Exists in LinkedHashSet in Java patelnagendra1 Follow Improve Article Tags : Java Java Programs java-LinkedHashSet Practice Tags : Java Similar Reads How to Check if LinkedHashMap is Empty in Java? The LinkedHashMap is just like HashMap with an additional feature of maintaining an order of elements inserted into it. HashMap provided the advantage of quick insertion, search, and deletion but it never maintained the track and order of insertion which the LinkedHashMap provides where the elements 2 min read How to Sort LinkedHashSet Elements in Descending Order in Java? The LinkedHashSet is an ordered version of HashSet that maintains a doubly-linked List across all elements. When the iteration order is needed to be maintained this class is used. When iterating through a HashSet the order is unpredictable, while a LinkedHashSet iteration is through the elements in 2 min read How to Find the Element Index in LinkedHashSet in Java? LinkedHashSet is used to store distinct items and get the items in which order they were inserted in Java. LinkedHashSet does not store values based on the index. But there are some methods to find the element index in LinkedHashSet in Java. Method 1: (By converting LinkedHashSet to ArrayList) To fi 4 min read How to Print LinkedHashSet Elements in Java? LinkedHashSet is a child class of HashSet in which duplicates are not allowed but the insertion order is preserved. The elements are printed in the same order in which they were inserted. There are several ways to print LinkedHashSet elements: By simply printing the elementsBy using enhanced for loo 4 min read Java Program to Get Elements By Index from LinkedHashSet LinkedHashSet is a pre-defined class in Java that is similar to HashSet. Unlike HashSet In LinkedHashSet insertion order is preserved. In order to get element by Index from LinkedHashSet in Java, we have multiple ways.Illustration:Input : 2, 3, 4, 2, 7;Processing : index = 4;Output : Element at inde 4 min read Like