How to Merge Two LinkedHashSet Objects in Java? Last Updated : 11 Dec, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Use the addAll() method to merge two LinkedHashSet objects or append elements of one LinkedHashSet object to another LinkedHashSet object. Comparing with the set, addAll() method is used as Union. The addAll method adds all the elements of the specified collection to this set object. Example: Input : List1 = [1,2,3], List2 = [3, 4, 5] Output: [1, 2, 3, 4, 5] Input : List1 = ['a', 'b', 'c'], List2 = ['d'] Output: ['a', 'b', 'c', 'd']Syntax: boolean addAll(Collection<? extends E> collection) Parameters: This is the collection containing elements to be added to this list. Example: Java // How to merge two LinkedHashSet objects in Java? import java.util.LinkedHashSet; public class MergedLinkedHashSet { public static void main(String[] args) { LinkedHashSet<String> lhSetColors1 = new LinkedHashSet<String>(); lhSetColors1.add("yellow"); lhSetColors1.add("white"); lhSetColors1.add("black"); LinkedHashSet<String> lhSetColors2 = new LinkedHashSet<String>(); lhSetColors2.add("yellow"); lhSetColors2.add("red"); lhSetColors2.add("green"); /* * To merge two LinkedHashSet objects or * append LinkedHashSet object to another, use the * addAll method */ lhSetColors1.addAll(lhSetColors2); System.out.println("Merged LinkedHashSet: " + lhSetColors1); } } OutputMerged LinkedHashSet: [yellow, white, black, red, green] Comment More infoAdvertise with us Next Article How to Print LinkedHashSet Elements in Java? P patelnagendra1 Follow Improve Article Tags : Java Java Programs java-LinkedHashSet Practice Tags : Java Similar Reads How to Merge Two LinkedHashMaps in Java? In Java, LinkedHashMap is a class that extends HashMap and maintains the order of elements based on the order of insertion. Merging two LinkedHashMaps involves combining their key-value pairs while ensuring that the order is preserved. In, this article we will explore different approaches to merging 3 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 How to Find User Defined Objects From LinkedHashSet in Java? LinkedHashSet is used to store elements in which order they were inserted. 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 lets us iterate through the elements in the order in which they were i 3 min read How to Convert LinkedHashMap to List in Java? LinkedHashMap is predefined class in Java which is similar to HashMap, contains key and its respective value unlike HashMap, in LinkedHashMap insertion order is preserved. We to convert LinkedHashMap to ArrayList. A Map store data in pair of Key and Value while converting a LinkedHashMAp to ArrayLis 2 min read How to Convert ArrayList to LinkedHashSet in Java? ArrayList is a data structure that overcomes the shortcomings of the common array in Java wherein the size has to be explicitly specified beforehand. The length of the array data structure cannot be modified which is taken care of the ArrayList data structure. This data structure is also known as th 8 min read How to Print all Keys of the LinkedHashMap in Java? LinkedHashMap is a predefined class in Java that is similar to HashMap, contains a key and its respective value. Unlike HashMap, In LinkedHashMap insertion order is preserved. The task is to print all the Keys present in our LinkedHashMap in java. We have to iterate through each Key in our LinkedHas 2 min read Like