0

I have syntax:

List<double[]> x = new ArrayList<double[]>();
x.add(new double[] { 5,6,7,8 });

How to add 5,6,7,8 automatically? like this

for (int i=5; i<=8; i++) {
**CODE**
}

List<double[]> x = new ArrayList<double[]>();
x.add(new double[] { **CODE** });

So, I want to replace **CODE**, what is that **CODE**? is it possible? Sorry bad English

1
  • 1
    If my answer worked for you dont hesitate to accept it :) Commented Mar 31, 2013 at 22:21

2 Answers 2

3
double[] d = new double[4];
for (int i=5; i<=8; i++) {
    d[i-5] = i; 
}

List<double[]> x = new ArrayList<double[]>();
x.add(d);

Didnt test but should work if u wanna add a Array to an ArrayList.

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

Comments

0

Replace double with Double in your code. Like this:

List<Double> x = new ArrayList<Double>();
for (int i=5; i<=8; i++) {
   x.add(new Double((double)i));
}

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.