943,846 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1470
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Oct 13th, 2008
0

hashmap

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
codered152 is offline Offline
36 posts
since Jan 2008
Oct 13th, 2008
0

Re: hashmap

HashMap

Java Syntax (Toggle Plain Text)
  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
Java Syntax (Toggle Plain Text)
  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.
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,259 posts
since Dec 2007
Oct 13th, 2008
0

Re: hashmap

I think you may have meant
Java Syntax (Toggle Plain Text)
  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().
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Oct 13th, 2008
0

Re: hashmap

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.
Reputation Points: 10
Solved Threads: 0
Light Poster
codered152 is offline Offline
36 posts
since Jan 2008
Oct 13th, 2008
0

Re: hashmap

Click to Expand / Collapse  Quote originally posted by codered152 ...
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.
Reputation Points: 10
Solved Threads: 0
Light Poster
codered152 is offline Offline
36 posts
since Jan 2008
Oct 13th, 2008
0

Re: hashmap

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?
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Oct 13th, 2008
0

Re: hashmap

Click to Expand / Collapse  Quote originally posted by Ezzaral ...
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.
Reputation Points: 10
Solved Threads: 0
Light Poster
codered152 is offline Offline
36 posts
since Jan 2008
Oct 13th, 2008
0

Re: hashmap

I doubt that is the case. Either you are not describing your question clearly enough or you misunderstood the requirement.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Oct 13th, 2008
0

Re: hashmap

Here's what you can do:
java Syntax (Toggle Plain Text)
  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...
Reputation Points: 7
Solved Threads: 6
Junior Poster
new_2_java is offline Offline
127 posts
since Apr 2007
Oct 13th, 2008
0

Re: hashmap

What on earth is that supposed to accomplish?
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: help with reaction on this...
Next Thread in Java Forum Timeline: Problem reading an infile





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC