I have a TreeMap with a set of 'Key and Value' pairs. How can I get both Key and Value at a particular Index of the TreeMap?
EDIT : @TO-ALL : Thanks. But I know how to implement it by using an extra ArrayList. I just thought is there any way to achieve this without using an extra ArrayList.
If you really want to use TreeMap and get by position, you can use the following:
key => treemap.keySet().toArray()[0]
value => treemap.get(key);
OR (if you just want value)
treemap.values().toArray()[0];
But I would suggest you use iterator, as in the above method, it needs to create array whenever you want to find (so not so efficient) and also you should be careful enough to make sure index don't go out of reach.