• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

floats and Float objects

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there. Just a quick question on floats and Float objects. I am trying to insert into a Properties object a String and a float. Code is as follows

Properties props = new Properties();
props.put(String value, float value); //this gives the error

Error(61,18): method put(java.lang.String, float) not found in class java.util.Properties

I know there is the idea of the Float object as oppose to the simple float value. Will inserting a Float object overcome my problem and if so how do I convert a float into a Float object. Cheers Joe
 
Bartender
Posts: 9620
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the documentation for java.util.Properties. Especially the line that says:


Each key and its corresponding value in the property list is a string.


So you can't set a property to a Float or a float. You can, however, convert a float to a String using String.valueOf(). To do the conversion in the other direction, consult the documentation for java.lang.Float.
 
Where all the women are strong, all the men are good looking and all the tiny ads are above average:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic