I have a 2d char array and i need to find the position of a specific char in the array. what method can i use.

return Arrays.binarySearch(this.matrixCopy, "S");

does not work it keeps returning -1 when there is an S in the array.

never really used 2d arrays, but when I did (as a student) I took the easy way:

public class SearchChar {
    
    public static void main(String args[]){
        char toFind = 'a';// determin the char you want;
char[][] array2d = {{'1','k','d'},{'a','p'}};//a given array

int a = -1;
int b = -1;
System.out.println("eerste lengte: " + array2d.length);
System.out.println("tweede lengte: " + array2d[0].length);
for ( int i = 0; i < array2d.length; i++){
    System.out.println("i = " + i);
  for ( int j = 0; j < array2d[i].length; j++){
      char test = array2d[i][j];
          if (test == toFind){
       a = i;
       b = j;
  }
  }
}
System.out.println("a : " + a + " b : " + b);
    }

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.