how to pass the value of a 2-d array index to a 1-d array index in android?I want to place this code inside a switch case.
int r1[]= int M[0][0];
how to pass the value of a 2-d array index to a 1-d array index in android?I want to place this code inside a switch case.
int r1[]= int M[0][0];
You want to flatten the array
Dependent on what version you are using these are a couple options!
Using Java 8 Streams:
int[] r1= Stream.of(M).flatMapToInt(IntStream::of).toArray();
Older versions of Java:
int[] r1 = new int[size];
int index = 0;
for (int[] x: M) { // loop through the rows
for (int y: x) // loop through the values
array[index++] = y;
}
Dynamically allocating the values using an ArrayList is an option:
ArrayList<int> r1 = new ArrayList<>();
case R.id.b1:
int val=M[0][0];
r1.add(val);