Start Coding Now
📊 Array Programsbeginner1 methods

Merge Two Arrays in Java

Program to merge two arrays into a single array.

Last updated: 11 January 2026

Method 1: Using Loop

Copy elements manually.

import java.util.Arrays;

public class MergeArrays {
    public static void main(String[] args) {
        int[] first = {10, 20, 30};
        int[] second = {40, 50, 60};
        int aLen = first.length;
        int bLen = second.length;
        
        int[] result = new int[aLen + bLen];
        
        System.arraycopy(first, 0, result, 0, aLen);
        System.arraycopy(second, 0, result, aLen, bLen);
        
        System.out.println("Merged Array: " + Arrays.toString(result));
    }
}
Output:
Merged Array: [10, 20, 30, 40, 50, 60]

Explanation

Create a new array of size (len1 + len2) and copy elements using System.arraycopy().

Frequently Asked Questions

Try This Program

Copy this code and run it in our free online Java compiler.

Open Java Compiler