concatenate array and return a new array - Android java.lang

Android examples for java.lang:array union merge

Description

concatenate array and return a new array

Demo Code

import java.lang.reflect.Array;
import java.util.List;

public class Main{

    public static Object[] concatenate(Object[] first, Object[] second) {
        Object[] result = new Object[first.length + second.length];
        for (int i = 0; i < first.length; i++) {
            result[i] = first[i];//from   www . j  av  a  2  s.com
        }
        for (int i = 0; i < second.length; i++) {
            result[i + first.length] = second[i];
        }
        return result;
    }
    public static int[] concatenate(int[] first, int[] second) {
        int[] result = new int[first.length + second.length];
        for (int i = 0; i < first.length; i++) {
            result[i] = first[i];
        }
        for (int i = 0; i < second.length; i++) {
            result[i + first.length] = second[i];
        }
        return result;
    }
    public static boolean[] concatenate(boolean[] first, boolean[] second) {
        boolean[] result = new boolean[first.length + second.length];
        for (int i = 0; i < first.length; i++) {
            result[i] = first[i];
        }
        for (int i = 0; i < second.length; i++) {
            result[i + first.length] = second[i];
        }
        return result;
    }

}

Related Tutorials