aspose file tools*
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
Author

Problem with Populating an ArrayList of Floats

Rob Sweeny
Greenhorn

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);
______________________^

Thanks

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:

fishLengthList.add(10.0f);


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


SCJA
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
Rancher

Joined: Mar 09, 2009
Posts: 600
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Problem with Populating an ArrayList of Floats