Java 参考增量指数

Java 参考增量指数,java,arrays,Java,Arrays,我得到了一个整数,它表示存储在数组中的值。如何增加它引用的索引 int[] pos={0,1,2}; int thisPos=pos[1]; thisPos=pos[++]; //-> thisPos=pos[2]; 你可以用 pos[2] 如果要跟踪某个位置,则需要一个变量来保存它: int i = 1; thisPos = pos[i]; i = i+1; thisPos = pos[i]; 您需要单独声明索引: int index = 1; int thisPos = pos[

我得到了一个整数,它表示存储在数组中的值。如何增加它引用的索引

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

pos[2]
如果要跟踪某个位置,则需要一个变量来保存它:

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

您需要单独声明索引:

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

您必须扫描数组以找到该值,并希望该值在数组中是唯一的,然后获取其索引,然后增加该索引。e、 g

curPos = find_index_for_value(pos[1]); // index = 1
curPos = curPos + 1;
thisPos = pos[curPos];
但是就像我说的,你必须确保数组中没有重复的值。e、 g.如果数组是

{0,1,2,3,4,0,1,2,3,5}
 a b c d e f g h i j

curPos是2-那么你在这两个2值中处于哪一个?c或h?

它不涉及任何索引。thisPos是int值的容器。仅此而已。变量thisPos不引用任何索引。它只是包含一个恰好与pos[1]中存储的值相同的值。不能将其递增到下一个数组元素。你所能做的最好的事情就是存储这个位置,增加这个位置,然后索引到那个位置。我觉得你误解了这个问题。至少,这不是我对OP想要什么的印象。怎么会这样?thisPos从数组中有一个值,OP希望移动到该值之后的下一个数组条目。