public static void main(String[] args) { int array1[]={2,3,4,6}; int array2[]={1,2,5,4,5,7,2,3}; System.out.print("my Array 1 = " + Arrays.toString(array1)); System.out.print("\n\nmy Array 2 = " + Arrays.toString(array2)); System.out.println("\n\n\nFrom Array1 to Array2: " + Arrays.toString(append(array1,array2))); System.out.println("\n\nFrom Array2 To Array 1: " + Arrays.toString(append(array2, array1))); } public static int[] append(int[] array1, int[] array2) { int array1Length = array1.length; int array2Length = array2.length; int[] array3 = new int[array1Length+array2Length]; for(int i=0;i<array1Length;i++) { array3[i]=array1[i]; } for(int i=0;i<array2Length;i++) { array3[array1Length+i]=array2[i]; } return array3; } } //OUTPUT: my Array 1 = [2, 3, 4, 6] my Array 2 = [1, 2, 5, 4, 5, 7, 2, 3] From Array1 to Array2: [2, 3, 4, 6, 1, 2, 5, 4, 5, 7, 2, 3] From Array2 To Array 1: [1, 2, 5, 4, 5, 7, 2, 3, 2, 3, 4, 6]
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter