A very basic question but I am having a little bit of trouble, I am very new to Java (my only experience prior is VB.NET which I developed on for a couple of years but never really used any OOP principles)
I need an array implementation for a load of decimal numbers. I'm not sure how many I'll have so I need an array which can dynamically change it's size and I've been told an ArrayList is the way to go.
So I've tried this:
ArrayList<double> xCo = new ArrayList<double>();
And my compiler gets angry and asks me for a "reference" in space of where double goes. I'm certain I'm misunderstanding something the whole declaration process of these things so how am I supposed to go about doing it?
Thanks in advance :)
You can't use primitives in generics, use Double
instead. Note the capitalization.
You cannot use java primitives in Generics , instead you have to use java primitive wrapper types
Change it to
ArrayList<Double> xCo = new ArrayList<Double>();
Check this tutorial to learn more on Generics
使用Double而不是double,希望你导入了java.util.Arraylist包
你想要Double
,而不是double
:
ArrayList<Double> xCo = new ArrayList<Double>();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.