Java - Write code to merge Array

Requirements

Write code to merge Array

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String[] a = new String[] { "1", "abc", "level", null,
                "book2s.com", "asdf 123" };
        String[] b = new String[] { "1", "abc", "level", null,
                "book2s.com", "asdf 123" };
        System.out.println(java.util.Arrays.toString(mergeArray(a, b)));
    }/*from   w  ww  . j av  a 2  s.  c o m*/

    public static String[] mergeArray(String[] a, String[] b) {
        if (a == null) {
            return b;
        }
        if (b == null) {
            return a;
        }
        String[] newArray = new String[a.length + b.length];
        System.arraycopy(a, 0, newArray, 0, a.length);
        System.arraycopy(b, 0, newArray, a.length, b.length);
        return newArray;
    }
}

Related Exercise