Results 1 to 3 of 3
- 05-05-2012, 01:01 AM #1
Member
- Join Date
- May 2012
- Posts
- 1
- Rep Power
- 0
removing from a hashmap and adding to the end
hi guys,
Just come across the forum, and it seems a great place to learn for someone only just starting out in java!
Wondering if anyone can assist
I am trying to write a method that represents a rota by removing an entry in a hashmap and adding it to the end, however the code I have at the moment works for removing the entry but when I put it back it goes in its original place:
ThanksJava Code:public void cleaningRota(String justCleaned) { ArrayList<Integer> removedKey = cleanVolunteers.remove(justCleaned); cleanVolunteers.put(justCleaned, removedKey); System.out.println(removedKey);//ignore - used for testing }
- 05-05-2012, 01:29 AM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,619
- Rep Power
- 5
Re: removing from a hashmap and adding to the end
Recommend reading on how a HashMap works under the hood - and this is clearly stated in the API
This includes the order of entry. If you need to maintain the order of entry of the keys within a Map, use a LinkedHashMapThis class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time.Last edited by doWhile; 05-05-2012 at 01:40 AM.
- 05-05-2012, 01:34 AM #3
Re: removing from a hashmap and adding to the end
HashMap is unordered, so the concept of 'adding to the end' doesn't apply. Read the API for the Map interface and go through the implementing classes; you'll find there's a Map implementation that has
dbpredictable iteration order.
cat's out of the bag!Why do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
removing and adding SWING components
By Athlon* in forum AWT / SwingReplies: 1Last Post: 12-06-2011, 06:12 PM -
Adding and removing components from a GridBagLayout
By peterhabe in forum New To JavaReplies: 4Last Post: 09-19-2010, 10:13 PM -
problem with removing element from HashMap
By checho in forum New To JavaReplies: 15Last Post: 01-10-2010, 01:10 PM -
Adding \ removing items from Jlist
By Desperado in forum AWT / SwingReplies: 10Last Post: 12-17-2009, 12:48 PM -
Adding and removing panels dynamically
By kbyrne in forum AWT / SwingReplies: 1Last Post: 04-12-2008, 08:28 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks