Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我构造一个二维数组,例如
Object[][] myArray = new Object[5][5];
我使用for循环遍历数组,有没有办法检查我当前的位置是否是某个索引?
喜欢
if(myArray[3][4]) { ..... }
像这样?
for(int i = 0; i < myArray.length; i++) { Object[] row = myArray[i]; for(int j = 0; j < row.length; j++) { Object o = row[j]; foo(o); if(i == 3 && j == 4) bar(o); } }
但是你为什么要这样做而不是bar(myArray[3][4])在循环后调用呢?
bar(myArray[3][4])