简体   繁体   中英

Searching only the first dimension of a 2d array

Let's say I have two arrays (one being one dimension and the next being 2d)

    int[] attack = {0,1};
    int[][] coords = {{0,1,2,3,4},{0,1,2,3,4}};

And I want to search for attack[0] in only the first dimension of coords?

How would I go about doing this?

Perhaps this is what you mean?

for(int[] a : coords) {
    if(a[0] == attack[0]) {
        // do something
    }
}
for(int element : coords[0]) {
    if(element == attack[0]) {
        // do stuff
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM