wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Maps Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Maps" Watch "Maps" New topic
Author

Maps

Sherry Jacob
Ranch Hand

Joined: Jun 29, 2005
Posts: 128
Hi All,
I made this simple program for inserting elements in2 a Map and then displaying the elements of the Map :



THe program does not compile...it gives an error :



Why ? The put() method takes two objects as parameters.
I have converted the primitive values to their respective Object types...still the error ??

Please help...


<strong><br />Cheers !!<br /> <br />Sherry<br /></strong><br />[SCJP 1.4]
Steve McCann
Ranch Hand

Joined: Oct 20, 2004
Posts: 81
Hi Sherry

You can't cast from a primitive to an Object. Try creating a new Integer rather than casting, e.g.

Steve
[ August 04, 2005: Message edited by: Steve McCann ]
Sherry Jacob
Ranch Hand

Joined: Jun 29, 2005
Posts: 128
Originally posted by Steve McCann:
Hi Sherry

You can't cast from a primitive to an Object. Try creating a new Integer rather than casting, e.g.

Steve

[ August 04, 2005: Message edited by: Steve McCann ]



eeeeeeh....what's up doc ? Thanx abunch Steve...it worked. I made an elementary mistake !!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Maps
 
Similar Threads
Help Me!
SUN sample question
identifier expected
Auto-Naming of references with integers
Problem using pollLastEntry() method from TreeMap