• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

getting array values from HashMap!!!

 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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:
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SORRY!!!


i got Nithes....you are RIGHT!!!

thanks lot

regards,
seetharaman
 
Sheriff
Posts: 22650
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Did Steve tell you that? Fuh - Steve. Just look at this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic