join String Array - Java java.lang

Java examples for java.lang:String Array

Description

join String Array

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String[] oldArray = new String[] { "1", "abc", "level", null,
                "java2s.com", "asdf 123" };
        String oldArray2 = "java2s.com";
        System.out.println(java.util.Arrays.toString(joinStringArray(
                oldArray, oldArray2)));//w  w  w . j  a  v  a  2 s . c  o  m
    }

    public static String[] joinStringArray(String[] oldArray,
            String... oldArray2) {
        String[] newArray = new String[oldArray.length + oldArray2.length];
        int i;

        for (i = 0; i < oldArray.length; ++i) {
            newArray[i] = oldArray[i];
        }

        for (i = 0; i < oldArray2.length; ++i) {
            newArray[i + oldArray.length] = oldArray2[i];
        }

        return newArray;
    }
}

Related Tutorials