| Author |
getting array values from HashMap!!!
|
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
Hi All, i am having problem in getting array value from hashmap using its get method.. see below ------------------------------------------------------------- HashMap map=new HashMap(); double[] month_with_data_swap=new double[10]; //values from database compoffadded1+=Double.valueOf(rs.getString("comoffadded")).doubleValue(); leavetaken1+=Double.valueOf(rs.getString("leavetaken")).doubleValue(); compoffinhand1=Double.valueOf(rs.getString("compoffinhand")).doubleValue(); leaveinhand1=Double.valueOf(rs.getString("leaveinhand")).doubleValue(); balance1=Double.valueOf(rs.getString("balance")).doubleValue(); month_with_data_swap[0]=compoffadded1; month_with_data_swap[1]=leavetaken1; month_with_data_swap[2]=compoffinhand1; month_with_data_swap[3]=leaveinhand1; month_with_data_swap[4]=balance1; map.put(months[i],month_with_data_swap); --------------------------------------------------------------------- now tell me how to get the value from map... when i try to print map..i get like below ---------------------------- {Apr=[D@e0e1c6}//months[i]=Apr --------------------- please can anyone tell me that how to get values back from HashMap.. thanks & regards, seetharaman
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
Hi All, seetharaman again.... see here i giving clearly!!! output: ^^{Apr=[D@3e25a5}//!!! --------------------------------- HashMap hm=new HashMap(); double[] month=new double[10]; month[0]=2.0; month[1]=4.0; hm.put("Apr",month); System.out.println("^^"+hm); ------------------------------------------- HOW TO GET my values back from map.. please explain me.....hope this is clear for you thanks & regards, seetharaman
|
 |
Nitesh Kant
Bartender
Joined: Feb 25, 2007
Posts: 1638
|
|
Originally posted by seetharam venk: HOW TO GET my values back from map..
You will get an array object back from the Map. You can use it as you would otherwise use an array. A sample code:
|
apigee, a better way to API!
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
Hi Nitesh, you are not getting me...!!! i want to assing values from the particular index....then again it will loop and override..please you see my first posted... then please reply me.. thanks & regards, seetharaman
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
SORRY!!! i got Nithes....you are RIGHT!!! thanks lot regards, seetharaman
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
For your information, [D@3e25a5 is the string representation of your array. It is built as follows: - [ to indicate an array - D for the type; double in this case - @ as a separator character - 3e25a5 as the hexidecimal representation of the hash code All arrays will look like this. The type is as follows: - B for byte - S for short - C for character - I for int - L for long - F for float - D for double - Z for boolean - the class name followed by ; for classes. Example: [java.lang.String;@xxxxx
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
yashbir sachdev
Greenhorn
Joined: Apr 21, 2008
Posts: 2
|
|
Hello Seetharam, You can do something like this HashMap map=new HashMap(); double[] month_with_data_swap=new double[10]; final int noOfMonths = 12; //ur index of months[i] for(int i =0; i<noOfMonths; i++) { //values from database compoffadded1+=Double.valueOf(rs.getString("comoffadded")).doubleValue(); leavetaken1+=Double.valueOf(rs.getString("leavetaken")).doubleValue(); compoffinhand1=Double.valueOf(rs.getString("compoffinhand")).doubleValue(); leaveinhand1=Double.valueOf(rs.getString("leaveinhand")).doubleValue(); balance1=Double.valueOf(rs.getString("balance")).doubleValue(); month_with_data_swap[0]=compoffadded1; month_with_data_swap[1]=leavetaken1; month_with_data_swap[2]=compoffinhand1; month_with_data_swap[3]=leaveinhand1; month_with_data_swap[4]=balance1; map.put("months"+(i+1), month_with_data_swap); //Keys will be "months1", "months2",etc. } Later to retrieve the values or modify it, you can use for(int i =0; i<noOfMonths; i++) { (typecast it as per your processing logic)map.get("months" + (i+1)); } Dear Rob, thanks for the explanation. I learnt something new today  [ April 22, 2008: Message edited by: yashbir sachdev ]
|
 |
 |
|
|
subject: getting array values from HashMap!!!
|
|
|