java - Iterating over a key set of a LinkedHashMap -


is possible retrieve next (next, in next key value has been inserted) key value of linkedhashmap?
e.g. current key value 2 , next key value 4. want use value of next key without setting iterator (or whatsoever) 1 index further. apparently using 1 iterator doesn't seem job. idea cast set returned myhashmap.keyset() other implementing class not sure if possible retrieve next element.

any ideas?

assume there linkedhashmap<k,v> linkhashmap, define custom method getnextkey takes parameter index , return next index value if valid.

code snippet (not working code)-

public k getnextkey(int index){     // put check if index valid     k[] keyarray = linkedhasmap.keyset.toarray(new k[linkedhasmap.size()]);     return k[index+1]; } 

Comments