- Order: Both LinkedHashMap and LinkedHashSet maintain the insertion order. Elements get sorted in the same sequence in which they have been added.
- Synchronized: Both are not synchronized and must be synchronized externally.
- Duplicates: LinkedHashMap does a mapping of keys to values so not have duplicates and LinkedHashSet simply stores a collection of things with no duplicates.
- Memory: Keeping the insertion order in both LinkedHashmap and LinkedHashset have additional associated costs, both in terms of spending additional CPU cycles and needing more memory.
Difference between linkedhashmap and linkedhashset:
- Replacement: LinkedHashMap replace value with duplicate key while LinkedHashSet not change original value.
- Operation: LinkedHashMap does a mapping of keys to values while LinkedHashSet simply stores a collection of things.
- Null Object: LinkedHashMap have elements in key value pair so have only one null key and multiple null value, while LinkedHashSet simply stores a collection of things with one null value.
- Constructor: The LinkedHashMap accepts five types of constructors:
LinkedHashMap(), LinkedHashMap(int capacity), LinkedHashMap(int capacity, float fillRatio),
LinkedHashMap(int capacity, float fillRatio, boolean Order)
The LinkedHashSet accepts four types of constructors:
HashSet(), HashSet(Collection C), LinkedHashSet(int size),
LinkedHashSet(int capacity, float fillRatio)
LinkedHashMap:LinkedHashMap lhm = new LinkedHashMap();
LinkedHashSet:LinkedHashSet hs = new LinkedHashSet();
- Class Declaration:
LinkedHashMap:public class LinkedHashMap extends HashMap implements Map
LinkedHashSet:public class LinkedHashSet extends HashSet implements Set, Cloneable, Serializable
100 Amit null Anuj 101 Vijay 102 Saurav
Amit null Vijay Rahul
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- LinkedHashMap in Java
- LinkedHashMap get() Method in Java
- LinkedHashMap removeEldestEntry() Method in Java
- LinkedHashMap clear() Method in Java
- LinkedHashMap containsKey() Method in Java
- Differences between TreeMap, HashMap and LinkedHashMap in Java
- LinkedHashSet in Java with Examples
- LinkedHashSet contains() method in Java
- Print characters and their frequencies in order of occurrence using a LinkedHashMap in Java
- LinkedHashSet equals() method in Java with Example
- LinkedHashSet hashCode() method in Java with Example
- LinkedHashSet remove() method in Java
- LinkedHashSet size() method in Java
- LinkedHashSet retainAll() method in Java with Example
- Difference Between LinkedList and LinkedHashSet in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.