Errelion Errelion - 2 months ago 24
Java Question

Increment index of reference

I've got an integer that refers to a value stored in an array. How can i increment the index it refers to?

int[] pos={0,1,2};
int thisPos=pos[1];
thisPos=pos[++]; //-> thisPos=pos[2];

Answer

You need to declare the index separately:

int index = 1;
int thisPos = pos[index];
index++;
thisPos = pos[index];