jQuery in Action, 3rd edition
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "HashMap" Watch "HashMap" New topic


manikandan malathy

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>?

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46383
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

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");

I agree. Here's the link: http://aspose.com/file-tools
subject: HashMap
It's not a secret anymore!