I'm trying to initialize an ArrayListto use later in my code, but it seems like it doesn't accept doubles.
public ArrayList<double> list = new ArrayList<double>();
It gives an error under 'double', sayin "Syntax error on token "double", Dimensions expected after this token"
An ArrayList doesn't take raw data types (ie, double ). Use the wrapper class (ie, Double ) instead : public ArrayList<Double> list = new ArrayList<>(); Also, as of Java 7, no need to specify that it's for the Double class, it will figure it out automatically, so you can just specify <> for the ArrayList.
Look at this: ArrayList<Double> list = new ArrayList<Double>(); it creates a list that can only contain double values. A double is a variable type that can contain whole numbers and decimal numbers. So creating a list like this only allows the program to add numbers to the list: list.
An ArrayList
doesn't take raw data types (ie, double
). Use the wrapper class (ie, Double
) instead :
public ArrayList<Double> list = new ArrayList<>();
Also, as of Java 7, no need to specify that it's for the Double
class, it will figure it out automatically, so you can just specify <>
for the ArrayList.
You need to use the Wrapper class
for double
which is Double
. Try
public ArrayList<Double> list = new ArrayList<Double>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With