This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes put float into hashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "put float into hashMap" Watch "put float into hashMap" New topic
Author

put float into hashMap

Marko Debac
Ranch Hand

Joined: Aug 21, 2006
Posts: 121
Hi,

what I need to do that I can put float value into hashMap, because hash map takes only integer or string value


there is no
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Maps can take any Object, for both key and value. So:

is perfectly valid.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Lorenz Baylon
Ranch Hand

Joined: Jan 04, 2006
Posts: 99
Hi Marko,

Paul is right, however in Java 5, with autoboxing feature, a HashMap can take say a primitive key and a primitive value(e.g HashMap<int,float> , JVM in turn does the autoboxing behind the scenes for you.

Goodluck
[ June 04, 2007: Message edited by: lhorenz baylon ]

I just cant look, its killing me.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Originally posted by lhorenz baylon:
Hi Marko,

...(e.g HashMap<int,float> , JVM in turn does the autoboxing behind the scenes for you.


Note, you can't write HashMap<int, float>, that will result in a compiler error. The things between the angle brackets cannot be primitive types. Hoewever, you can make a HashMap<Integer, Float> and Java 5 autoboxing:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Lorenz Baylon
Ranch Hand

Joined: Jan 04, 2006
Posts: 99
oh yes, my bad, sorry and thanks
 
Consider Paul's rocket mass heater.
 
subject: put float into hashMap
 
Similar Threads
Auto-Naming of references with integers
About pageContext.setAttribute problem
JSTL Get value from HashMap inside HashMap
how to iterate a hashmap with key hashmap
HashMap bean with generic type parameters