Concatenation
Concatenation is the process to concatenate or join two distinct arrays.
Program to Concatenation of two arrays.
Example :-
Input- A[1,4,9,5,7,] / B[2,6,10,3,8]
Output- [1,4,9,5,7,2,6,10,3,8]
Program Solution :-
package QuipoHouse.ArrayOperations;
public class Concatenation {
public static void main(String[] args) {
int A[] = { 1, 4, 9, 5, 7 };
int B[] = { 2, 6, 10, 3, 8 };
int len = A.length + B.length;
int C[] = new int[len];
for (int i = 0; i < len; i++) {
if (i < A.length) {
C[i] = A[i];
} else {
C[i] = B[i - A.length];
}
}
System.out.println("---Element after Concatenation---");
System.out.print("[");
for (int x : C) {
System.out.print(x + " ");
}
System.out.print("]");
}
}
Output:
---Element after Concatenation---
[1 4 9 5 7 2 6 10 3 8 ]