Problem with HashMap
with regards to accessing elements from a HashMap, I am aware of two ways...
1. using a hashmap iterator.
2. using a standard java for loop.
However, i need to put a HashMap as a parameter of a recursive method, and i want to be able to access two things separately.
1. The first element of the HashMap.
2. Iterate through every element of the HashMap - EXCLUDING the first. (so they can be compared with the first for example)
Please advise on how this could be done.
Thanks in advance.
A HashMap doesn't have a "first" element, or at least not a "hard" first element. HashMap does not guarantee in which order things will be returned. Maybe you want to use a LinkedHashMap, then things will be returned in the same order in which the keys are added (modifications will not change the order). The other way is to get the HashSet of keys of using the keys() and call toArray on that and pass both the array and the HashMap (as well as the "current index") and calling get on the HashMap using the key from the array.
Who is creator of that HashMap and does it have to be HashMap at all?
If it has to be please explain what are K,V of HashMap.
This smells like List recursion to me...