I have been searching for hours through all the posts regarding LinkedHashMap but I seem to be missing the basics.
I will be generating a K,V sets from a db call, but no idea what each set will be. Some K,V will be processed and others not
I need to iterate the map, get the position (indexOf[i]??) + K(String).
This will then be passed out to anther method to ask how that K is to be processed (put into 2nd array)
Based on the 2nd array, I will then process the required K,V sets calling the position[i].
ie
1) poll db for info, records return as follows
– abc txt
– def blah
– ghi blah
– jkl txt
2) loop records and ask 2nd script what to do
– txt process like this …..
– blah do nothing
– save indexOf for quick referral as K may change value.
– change K,V if needed (spelling error corrected, remove spaces, strtolower etc)
3) based on further processing call indexOf as needed (K may have changed as above)
So is a LinkedHashMap the correct type to use?
From a PHP point of view seems easy, so I must be a bit thick on this.
Any code examples would be great.
It sounds like you need to be able to efficiently find elements in your structure both by key and by position.
One way to achieve this with standard Java containers is by using a
Mapin conjunction with anArrayList(both storing references to the same objects). The former enables fast lookups by key; the latter, by position.Insertions into such a structure would be
O(n). However, it sounds like you’re building the structure once, and not modifying it afterwards.Finally, if you don’t need to be able quickly locate an element given its key, you can lose the
Mapand just use anArrayList.