Skip to content

Instantly share code, notes, and snippets.

@rebekah
Created October 2, 2023 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rebekah/57318391b084d1e163a974da0c049793 to your computer and use it in GitHub Desktop.
Save rebekah/57318391b084d1e163a974da0c049793 to your computer and use it in GitHub Desktop.
public class MergeArrays {
public static void main(String[] args) {
int[][] arrays = {{1,2,3},{14,15,16,17}};
int mergedArrayLen = arrays[0].length + arrays[1].length;
int[] mergedArray = new int[mergedArrayLen];
int mergedArrayIndex = 0;
for(int i = 0; i < arrays.length; i++){
for(int j = 0; j < arrays[i].length; j++) {
mergedArray[mergedArrayIndex] = arrays[i][j];
mergedArrayIndex++;
}
}
for(int num: mergedArray){
System.out.print(num + " ");
}
System.out.println(" ");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment