Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add item to top of LinkedHashMap

Tags:

java

I am using LinkedHashMap in my code.This is my map:

LinkedHashMap<String, Conversation> conversationsMap=new LinkedHashMap<String, Conversation>();

I am adding items to this map with following line:

conversationsMap.put("test",Conversation);

But this line adding item to last.I need to add this item to top of this map.How can I do this ?

like image 827
Okan Avatar asked Oct 17 '25 17:10

Okan


1 Answers

LinkedHashMap retains insertion order.To add it to first you need to iterate through older map and insert values in a new map.

like image 68
Avi Avatar answered Oct 20 '25 07:10

Avi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!