简体   繁体   English

Java:用于存储双精度的ArrayList

[英]Java: ArrayList for storing doubles

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) 一个非常基本的问题,但我有点麻烦,我是Java的新手(我以前唯一的经验是VB.NET,我开发了几年但从未真正使用任何OOP原则)

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. 我不确定我有多少,所以我需要一个可以动态改变它的大小的数组,我被告知ArrayList是要走的路。

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. 您不能在泛型中使用基元,而是使用Double Note the capitalization. 注意大小写。

You cannot use java primitives in Generics , instead you have to use java primitive wrapper types 你不能在泛型中使用java原语,而是必须使用java原始包装类型

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>();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM