LinkedHashMap as an array
Posted on 2009-04-20
I have a LinkedHashMap - I think it retains the order in which you add items, kind of like an array. I want to access an element by an index. Something like:
LinkedHashMap<String, Apple> map = new LinkedHashMap<String, Apple>();
map.put("red", new Apple());
map.put("green", new Apple());
map.put("yellow", new Apple());
Apple entries = (Apple)(map.values().toArray(new Apple));
entries ; // green apple.
but that doesn't work - what's the right way to get the linked hashmap entries as an array?