![]() |
VOOZH | about |
LinkedHashMap is a pre-defined class in java like HashMap. The only difference between LinkedHashMap and HashMap is LinkedHashMap preserve insertion order while HashMap does not preserve insertion order. LinkedHashMap can convert into two Arrays in java where one array is for key in LinkedHashMap and another array for Values.
Example :
Input : LinkedHashMap = [2=6, 3=4, 5=7, 4=6] Output: Array of keys = [2, 3, 5, 4] Array of Values = [6, 4, 7, 6] Input : LinkedHashMap = [1=a, 2=b, 3=c, 4=d] Output: Array of keys = [1, 2, 3, 4] Array of Values = [a, b, c, d]
Algorithm :
Below is the implementation of the above approach:
Array of Key -> 2, 3, 5, 4, 6, Array of Values -> 6, 4, 7, 6, 8,
Time Complexity: O(n)