concatenate array - Android java.lang

Android examples for java.lang:array union merge

Description

concatenate array

Demo Code


//package com.java2s;

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];//w  w  w  .  j ava 2 s.  c  o  m
        }
        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