1

Best Java Collection to store key, value pairs and access its objects by Index or by key name

view story
linux-howto

http://stackoverflow.com – I want to store a key,values pair that allows me to get the values by its position (ordering must persist) or by its key name. I was thinking to use HashMap but i do not want to iterate through all values to get the value by index. I would need something like this: MyCollection<String, Object> objects = new MyCollection<String, Object>(); objects.put ("id", Object1); objects.put ("name", Object2); // And now access the values by index: Object obj1 = objects.get(1); // or by key name: Object obj2 = objects.getByKeyName("name"); What is the best collection to use (it must be and (HowTos)