connect Object Arrays - Java Collection Framework

Java examples for Collection Framework:Array Element

Description

connect Object Arrays

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        Object[] a1 = new String[] { "1", "abc", "level", null,
                "java2s.com", "asdf 123" };
        Object[] a2 = new String[] { "1", "abc", "level", null,
                "java2s.com", "asdf 123" };
        System.out//from   w  w w .  jav  a 2s .  co  m
                .println(java.util.Arrays.toString(connectArrays(a1, a2)));
    }

    public static Object[] connectArrays(Object[] a1, Object[] a2) {
        Object[] ret = new Object[a1.length + a2.length];
        for (int i = 0; i < a1.length; i++) {
            ret[i] = a1[i];
        }
        for (int i = 0; i < a2.length; i++) {
            ret[a1.length + i] = a2[i];
        }
        return ret;
    }
}

Related Tutorials