array concat java code example

Example 1: concatenate two arrays in java

import java.util.Arrays;

public class Concat {

    public static void main(String[] args) {
        int[] array1 = {1, 2, 3};
        int[] array2 = {4, 5, 6};

        int aLen = array1.length;
        int bLen = array2.length;
        int[] result = new int[aLen + bLen];

        System.arraycopy(array1, 0, result, 0, aLen);
        System.arraycopy(array2, 0, result, aLen, bLen);

        System.out.println(Arrays.toString(result));
    }
}

Example 2: how to print two arrays together

var array = [1,2,3,4,5,6,7,8,9,10]
var brray = ["one","two","three","four","five","six","seven","eight","nine","ten"]


for( i = 0 ; i < array.length ; i++){
 console.log(array[i], brray[i])