我正在尝试创建一个数组列表。这些数组包含 double 。当我使用 .add() 时,出现此错误:没有找到适合 add(double[]) 的方法 method.java.util.List.add(int,java.lang.Double[]) 不适用
这是我的代码的简化:
List<Double[]> allTris = new ArrayList<Double[]>();
List<String> tempList = new ArrayList<String>();
tempList.add("0.0");
tempList.add("1.0");
tempList.add("2.0");
double[] tri = new double[tempList.size()];
for(int i = 0; i < tempList.size(); i++) {
tri[i] = Double.parseDouble(tempList.get(i));
}
allTris.add(tri); //here is where my error is happening
最佳答案
改变
List<Double[]> allTris = new ArrayList<Double[]>();
至
List<double[]> allTris = new ArrayList<double[]>();
Double
(类)是 double
(基元)的包装器。它们是两个不同的东西。
关于Java:将 double 组添加到列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26793454/