[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: HashMap Troubles
Yes, Hashtable.get(String) returns an Object
which you can cast back to its original Class.
map.put("name","Deron");
System.out.println((String)map.get("name"));
If the hashtable has different types of objects
in it you can check it like this
Object o = map.get("name");
if (o instanceof String)
System.out.println((String)o);
or
try
{
System.out.println((String)o);
}
catch (ClassCastException x)
{
}
Similar tactics work with Vector elements.
(I dunno what an ArrayList is but it's probably
the same deal)
-----Original Message-----
From: Deron Pardue [mailto:dpardue@dspin.com]
Sent: Monday, September 10, 2001 4:55 PM
To: ajug-members@www.ajug.org
Subject: Re: HashMap Troubles
Hey. I'm not in a position to test this, but try the following:
System.out.println(map.get("name").toString());
the get() method returns an Object, not a String. I've had a similar
problem recently with Vectors and ArrayLists.