shortest way of filling an array with 1,2...n

Is there anything as quick as this in java? ( quick in coding)

int [] a = {1..99};

or I have to go for this:

int [] a=new int[100];
for (int i=0;i <100;++i){
a[i]=i;
}

Since Java 8 this is possible:

int[] a = IntStream.range(1, 100).toArray();

(And shorter than the other java 8 answer .).


Another alternative if you use Java 8:

int[] array = new int[100];
Arrays.setAll(array, i -> i + 1);

The lambda expression accepts the index of the cell, and returns a value to put in that cell. In this case, cells 0 - 99 are assigned the values 1-100.