like9orphanz
like9orphanz

Reputation: 55

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?

Upvotes: 0

Views: 110

Answers (2)

mclaassen
mclaassen

Reputation: 5138

Perhaps this is what you mean?

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

Upvotes: 1

SamC
SamC

Reputation: 31

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

Upvotes: 0

Related Questions