Merge two String array - Android java.lang

Android examples for java.lang:array union merge

Description

Merge two String array

Demo Code


//package com.java2s;
import java.lang.reflect.Array;

public class Main {
    public static String[] addAll(String[] array1, String[] array2) {
        if (array1 == null) {
            return clone(array2);
        } else if (array2 == null) {
            return clone(array1);
        }//from   ww  w .j a va2  s.  co  m
        String[] joinedArray = (String[]) Array.newInstance(array1
                .getClass().getComponentType(), array1.length
                + array2.length);
        System.arraycopy(array1, 0, joinedArray, 0, array1.length);
        System.arraycopy(array2, 0, joinedArray, array1.length,
                array2.length);
        return joinedArray;
    }

    public static String[] clone(Object[] array) {
        if (array == null) {
            return null;
        }
        return (String[]) array.clone();
    }
}

Related Tutorials