• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

Problem with Populating an ArrayList of Floats

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

How do I populate an ArrayList of Floats?
The below code gives me errors on compilation.





c:\code>javac LegalKeeperFish.java
LegalKeeperFish.java:7: cannot find symbol
symbol : method add(double)
location: class java.util.ArrayList<java.lang.Float>
___________ fishLengthList.add(10.0);
______________________^

Thanks

p.s. Is this the correct forum for a question like this?
 
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try declaring all your numbers like this:

fishLengthList.add(10.0f);


Putting an f after the number makes it a float, as opposed to a double.
 
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rob:

You've got your ArrayList set up correctly. The problem with your code is that floating point numbers default to doubles unless you mark them as floats. So, if you want Java to know you mean floats rather than doubles, you'll need to add an 'f' to the number, like this: 23.05f.

John.
 
This. Exactly this. This is what my therapist has been talking about. And now with a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic