Is there a way in Java to assign values en masse to an array?
To give an idea of what I'm trying to achieve, in Perl, you can do: @listofvalues = (1..$anynumber);
to add (in this case) all digits between 1 and $anynumber to the array @listofvalues.
Is there a Java equivalent, or another way of doing this in Java (with that kind of ease)?
So far, I have (with line numbers):
15 int limit = Integer.parseInt(args[0]);
16 double[] numbers = new double[limit];
17 int j = 0;
18 for (int i = 2; i < limit; i++) {
19 numbers[j] = i;
20 j++;
21 }
Is there a way to make this a little more eloquent?
Also, when I run this program - what code I've listed compiles without a complaint - I get the following error:
Exception in thread "main" java.lang.NullPointerException at Program.main(Program.java:19)
What gives?