Created
May 30, 2018 15:00
-
-
Save freaksgit/053947189db7ebda7757eac4dfbd900d to your computer and use it in GitHub Desktop.
Arr example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ExampleArr{ | |
public static void main(String[] args) { | |
int[][] arr2 = new int[3][4]; | |
Random random = new Random(); | |
for(int[] arr : arr2){ | |
for (int i = 0; i < arr.length; i++) { | |
arr[i] = random.nextInt(); | |
} | |
} | |
int newArrLength = arr2.length * arr2[0].length; | |
int[] newArr = new int[newArrLength]; | |
int offset = 0; | |
for (int arr[] : arr2){ | |
System.arraycopy(arr, 0, newArr, offset, arr.length); | |
offset = arr.length; | |
} | |
//var 2 | |
int pointer = 0; | |
for (int i = 0; i < arr2.length; i++) { | |
for (int j = 0; j < arr2[i].length; j++) { | |
newArr[pointer] = arr2[i][j]; | |
pointer++; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment