- 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
- 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 contains() method in Java
- LinkedHashSet in Java with Examples
- Print characters and their frequencies in order of occurrence using a LinkedHashMap in Java
- LinkedHashSet hashCode() method in Java with Example
- LinkedHashSet removeAll() method in Java with Example
- LinkedHashSet containsAll() method in Java with Example
- LinkedHashSet toString() method in Java with Example
- LinkedHashSet isEmpty() method in Java
- LinkedHashSet toArray(T) method in Java with Example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.