Java - Write code to do array Concatenate

Requirements

Write code to do array Concatenate

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String[] f = new String[] { "1", "abc", "level", null,
                "book2s.com", "asdf 123" };
        String[] s = new String[] { "1", "abc", "level", null,
                "book2s.com", "asdf 123" };
        System.out.println(java.util.Arrays
                .toString(arrayConcatenate(f, s)));
    }//from  ww  w  .  jav  a  2 s .  co  m

    public static String[] arrayConcatenate(final String[] f,
            final String[] s) {
        final int fLen = (f == null ? 0 : f.length);
        final int sLen = (s == null ? 0 : s.length);
        final int len = fLen + sLen;
        final String[] ret = new String[len];
        if (fLen > 0) {
            System.arraycopy(f, 0, ret, 0, fLen);
            if (sLen > 0) {
                System.arraycopy(s, 0, ret, fLen, sLen);
            }
        } else if (sLen > 0) {
            System.arraycopy(s, 0, ret, 0, sLen);
        }
        return ret;
    }
}

Related Exercise