hashmap

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2008
Posts: 36
Reputation: codered152 is an unknown quantity at this point 
Solved Threads: 0
codered152's Avatar
codered152 codered152 is offline Offline
Light Poster

hashmap

 
0
  #1
Oct 13th, 2008
hi guys

i have quiestion. i m using hashmap and now what i have to use hashmap value and put that in the int variable, can u guys help with that. i just need some hints so i can work on that. thank you
Best
Codered152
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,677
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 226
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: hashmap

 
0
  #2
Oct 13th, 2008
HashMap

  1. HashMap map = new HashMap();
  2. map.put("ONE",new Integer(1));
  3.  
  4. Integer integ = (Integer)map.get("ONE");
  5.  
  6. int value = integ.intValue();

or
  1. HashMap map = new HashMap<String,Integer>();
  2. map.put("ONE",1);
  3.  
  4. int integ = (Integer)map.get("ONE");
Last edited by javaAddict; Oct 13th, 2008 at 2:18 pm.
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,483
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 515
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: hashmap

 
0
  #3
Oct 13th, 2008
I think you may have meant
  1. Map<String, Integer> map = new HashMap<String, Integer>();
  2. map.put("ONE", 1);
  3.  
  4. int value = map.get("ONE");
Missing type on declaration and redundant cast on map.get().
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 36
Reputation: codered152 is an unknown quantity at this point 
Solved Threads: 0
codered152's Avatar
codered152 codered152 is offline Offline
Light Poster

Re: hashmap

 
0
  #4
Oct 13th, 2008
thank you for replies so soon. its making more sense for me now, but still there is some confusion, what i have is like this

private Map<Object, String> map= new HashMap <Object, String>();

and i need to create new int variable and use that to keep track of the that hashmap. so if u guys just explain me some more. thanks you.
Best
Codered152
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 36
Reputation: codered152 is an unknown quantity at this point 
Solved Threads: 0
codered152's Avatar
codered152 codered152 is offline Offline
Light Poster

Re: hashmap

 
0
  #5
Oct 13th, 2008
Originally Posted by codered152 View Post
thank you for replies so soon. its making more sense for me now, but still there is some confusion, what i have is like this

private Map<Object, String> map= new HashMap <Object, String>();

and i need to create new int variable and use that to keep track of the that hashmap. so if u guys just explain me some more. thanks you.

in other words can i do something like this.

int intVariable = map;

so all the hashmap value store in intVariable.
Best
Codered152
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,483
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 515
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: hashmap

 
0
  #6
Oct 13th, 2008
No, that does not make any sense at all. A Map is not an int by any conceptualization. Why do you feel you need to store a map in an int?
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 36
Reputation: codered152 is an unknown quantity at this point 
Solved Threads: 0
codered152's Avatar
codered152 codered152 is offline Offline
Light Poster

Re: hashmap

 
0
  #7
Oct 13th, 2008
Originally Posted by Ezzaral View Post
No, that does not make any sense at all. A Map is not an int by any conceptualization. Why do you feel you need to store a map in an int?
because that's what i been told to do.
Best
Codered152
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,483
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 515
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: hashmap

 
0
  #8
Oct 13th, 2008
I doubt that is the case. Either you are not describing your question clearly enough or you misunderstood the requirement.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 126
Reputation: new_2_java is an unknown quantity at this point 
Solved Threads: 6
new_2_java new_2_java is offline Offline
Junior Poster

Re: hashmap

 
0
  #9
Oct 13th, 2008
Here's what you can do:
  1. HashMap map = new HashMap();
  2. map.put(new Integer(1), new String("ONE"));
  3. map.put(new Integer(2), new String("TWO"));
  4. map.put(new Integer(3), new String("THREE"));
  5.  
  6. int one = Integer.parseInt(map.get(new Integer(1)).toString());
  7. and so on...
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,483
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 515
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: hashmap

 
0
  #10
Oct 13th, 2008
What on earth is that supposed to accomplish?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC