Results 1 to 7 of 7
Thread: [SOLVED] LinkedHashMap
- 04-03-2009, 05:46 AM #1
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
[SOLVED] LinkedHashMap
hi everyone,
i would like to know can we change the value of some "key"s in LinkedHashMap, and remain the order of "value" in LinkedHashMap?
- 04-03-2009, 06:19 PM #2
Member
- Join Date
- Dec 2008
- Posts
- 41
- Rep Power
- 0
yes, you would have to make new LinkedHashMap. go through all the elements of the HashMap and put it into the new HashMap with a different key. Other than that i dont believe there is a way to change the key. Hope this helps.
- 04-04-2009, 04:36 PM #3
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
thx for you suggestion
- 04-04-2009, 07:59 PM #4
Or write your own implementation that has a changeKey() method. It would involve a remove() and put() in the map, but not changing the list.
- 04-06-2009, 03:34 AM #5
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
after remove and put, the order of linkedHashMap will change...
- 04-06-2009, 03:53 AM #6
No, you write your own version of LinkedHashMap. The simplest - though not most efficient - method it to encapsulate bot a Map and a List, then LinkedHashMap.put() calls both Map.put() and List.add(). LinkedHashMap.changeKey(old, new) would call Map.remove(old) and Map.put(new), but leave the List alone.
Alternatively, you can probably have a look at the source code for Sun's LinkedHashMap and add the functionality there.
- 04-06-2009, 05:20 AM #7
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
Similar Threads
-
LinkedHashMap insertion whilst iterating
By Paul Richards in forum Advanced JavaReplies: 7Last Post: 02-13-2009, 01:24 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks