In Java, concatenating two arrays involves combining their elements into a new array.
Here is a simple Java program to concatenate two arrays:
public class ConcatenateArrays {
public static void main(String[] args) {
int[] array1 = {1, 2, 3};
int[] array2 = {4, 5, 6};
int length = array1.length + array2.length;
int[] result = new int[length];
int pos = 0;
for (int element : array1) {
result[pos] = element;
pos++;
}
for (int element : array2) {
result[pos] = element;
pos++;
}
System.out.println("Concatenated array: " + Arrays.toString(result));
}
}The program creates two integer arrays array1 and array2 with values {1, 2, 3} and {4, 5, 6} respectively.
It then determines the length of the new array by adding the lengths of the two arrays.
A new integer array result is created with the determined length.
The program then uses a for-each loop to iterate over each element in array1 and assigns it to the corresponding position in result.
It then does the same for each element in array2, assigning them to the remaining positions in result.
Finally, the concatenated array is printed to the console using Arrays.toString() method.
This program is a basic example of how to concatenate two arrays in Java.
It can be modified to concatenate arrays of different types or sizes.




