Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the first item of linkedhashmap [duplicate]

I am using LinkedHashMap. I will always process the first value and that can be deleted (if possible) so that during the next iteration I will again take the same first value from the map to process. What can I use to get the first value.

like image 277
PrabhaT Avatar asked Apr 30 '12 10:04

PrabhaT


1 Answers

You can use this to get the first element key:

 Object key = linkedHashMap.keySet().iterator().next();

then to get the value:

Object value = linkedHashMap.get(key);

and finally to remove that entry:

linkedHashMap.remove(key);
like image 178
krock Avatar answered Oct 24 '22 14:10

krock