Results 1 to 3 of 3
Thread: Problem with HashMap
- 04-14-2010, 08:28 PM #1
Member
- Join Date
- Jan 2010
- Posts
- 13
- Rep Power
- 0
Problem with HashMap
Hi,
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.
- 04-14-2010, 08:54 PM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
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.
- 04-14-2010, 09:40 PM #3
Senior Member
- Join Date
- Dec 2009
- Location
- Belgrade, Serbia
- Posts
- 364
- Rep Power
- 4
Similar Threads
-
Something like HashMap
By BigBear in forum New To JavaReplies: 4Last Post: 03-14-2010, 11:08 AM -
problem with removing element from HashMap
By checho in forum New To JavaReplies: 15Last Post: 01-10-2010, 01:10 PM -
How to create a new HashMap from a HashMap entries of other methods
By pandeyalok in forum Advanced JavaReplies: 7Last Post: 12-08-2009, 07:17 PM -
Iterating through HashMap problem
By JordashTalon in forum New To JavaReplies: 1Last Post: 01-28-2009, 11:28 PM -
hashmap
By tOpach in forum New To JavaReplies: 2Last Post: 09-24-2008, 12:55 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks