Results 1 to 2 of 2
Thread: Changing the values of a map.
- 02-25-2010, 11:57 PM #1
Member
- Join Date
- Nov 2009
- Posts
- 41
- Rep Power
- 0
Changing the values of a map.
Hello,
I have a variable which is of the type map with integers as keys and integers as values.
Now I want to write following method:
I have no idea how to do that. Can anyone help me?Java Code:public static void changeValues(int n){ //multiply the values of the map by n }
-
I'd get the keys out of the map via the keySet() method, then iterate through the map using this, getting the values, multiplying them and then putting them back in the map.
for e.g.,
Java Code:HashMap<String, Integer> map = new HashMap<String, Integer>(); map.put("Mon", 1); map.put("Tues", 2); map.put("Wed", 3); map.put("Thurs", 4); map.put("Fri", 5); int multiplier = 5; System.out.println(map); for (String key : map.keySet()) { int value = map.get(key); value *= multiplier; map.put(key, value); } System.out.println(map);
Similar Threads
-
HashMap contains all values but doesn't show all values
By xcallmejudasx in forum New To JavaReplies: 3Last Post: 05-10-2009, 11:35 PM -
its not changing bgcolor
By javanoobita in forum Java AppletsReplies: 1Last Post: 02-21-2009, 02:29 PM -
Changing the Jframe
By Nemo1959 in forum New To JavaReplies: 13Last Post: 09-19-2008, 03:58 PM -
Retaining DB values as well as Dynamically generated Values.. Help Needed !
By rajivjha in forum Advanced JavaReplies: 0Last Post: 05-22-2008, 10:53 AM -
Accessing boolean Values of another values in one class.
By a_iyer20 in forum Advanced JavaReplies: 4Last Post: 04-15-2008, 01:04 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks