0

I am trying to create a list of arrays. These arrays contain doubles. When I use .add() I get this error: no suitable method found for add(double[]) method.java.util.List.add(int,java.lang.Double[]) is not applicable

Here is a simplification of my code:

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

1 Answer 1

2

Change

List<Double[]> allTris = new ArrayList<Double[]>();

to

List<double[]> allTris = new ArrayList<double[]>();

Double (a class) is a wrapper around double (a primitive). They two different things.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.