wood burning stoves
The moose likes Beginning Java and the fly likes Problem with Populating an ArrayList of Floats Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with Populating an ArrayList of Floats" Watch "Problem with Populating an ArrayList of Floats" New topic

Problem with Populating an ArrayList of Floats

Rob Sweeny

Joined: Jan 14, 2010
Posts: 16
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);


p.s. Is this the correct forum for a question like this?
W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Posts: 710
Try declaring all your numbers like this:


Putting an f after the number makes it a float, as opposed to a double.

When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
John de Michele

Joined: Mar 09, 2009
Posts: 600

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.

I agree. Here's the link: http://aspose.com/file-tools
subject: Problem with Populating an ArrayList of Floats
It's not a secret anymore!