How can I flatten the 2 dimensions array int originalArray[][]
to 1 dimension array?
int a [] = {1,2,6,7,2}; int b [] = {2,44,55,2}; int c [] = {2,44,511,33}; int originalArray [][] = new int[][]{a,b,c};
Flattening array means converting a multidimensional array into a 1D array. We can use reshape(-1) to do this.
Rules for Declaring One Dimensional ArrayThe declaration must have a data type(int, float, char, double, etc.), variable name, and subscript. The subscript represents the size of the array. If the size is declared as 10, programmers can store 10 elements. An array index always starts from 0.
With Guava, you can use either
int[] all = Ints.concat(originalArray);
or
int[] all = Ints.concat(a, b, c);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With