Get the first item of linkedhashmap

If you are going to require the value and key it is best to use the EntrySet.

LinkedHashMap<Integer,String> map = new LinkedHashMap<Integer,String>();
Entry<Integer, String> mapEntry = map.entrySet().iterator().next();
Integer key = mapEntry.getKey();
String value = mapEntry.getValue();

Use the an Iterator on the value set - e.g.

Map map = new LinkedHashMap();
map.put("A", 1);
map.values().iterator().next();

From your question, it's not clear to me that a map is the best object to use for your current task.


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);