Easy Tutorial
❮ File Exist Collection Iterate ❯

Java Example - Array Merging

Java Examples

The following example demonstrates how to merge two arrays into one using the Arrays.toString() method of the List class and the list.addAll(Arrays.asList(array2)) method of the List class:

Main.java File

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
    public static void main(String args[]) {
        String a[] = { "A", "E", "I" };
        String b[] = { "O", "U" };
        List list = new ArrayList(Arrays.asList(a));
        list.addAll(Arrays.asList(b));
        Object[] c = list.toArray();
        System.out.println(Arrays.toString(c));
    }
}

The above code outputs the following result:

[A, E, I, O, U]

Java Examples

❮ File Exist Collection Iterate ❯