wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes HashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "HashMap" Watch "HashMap" New topic
Author

HashMap

manikandan malathy
Greenhorn

Joined: Sep 17, 2008
Posts: 13
How to store integer and string in a single hashmap?
rakesh sugirtharaj
Ranch Hand

Joined: Dec 16, 2007
Posts: 151
That can be done in a non generic map i suppose(That is not recommended of course). But why would you want to store a integer and String? Or may be you are asking about storing it like Map<Integer,String>?


Cheers!
RSR
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38107
    
  22
If you are mimicking a phone book you would want String (=name) as the Key and Integer (=number) as the Value. Only you can't store phone numbers beginning with 0 because they are interpreted as octal.
Neha Agarwal
Greenhorn

Joined: Mar 12, 2008
Posts: 16
This can be done in the following manner

import java.util.HashMap;


public class Test2{

public static void main (String args[])
{
HashMap hashMap = new HashMap();
hashMap.put(1, "One");
hashMap.put(2, "Two");
System.out.println(hashMap.get(1));
}

}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HashMap
 
Similar Threads
Nested if's
struts 2 s:radio tag
Finding a Specific Object in an ArrayList
WA #1.....word association
switch on String