concat All string in string array - Android java.lang

Android examples for java.lang:String Join

Description

concat All string in string array

Demo Code

import java.util.Arrays;

public class Main{

    public static String[] concatAll(String[] first, String... rest) {
        int totalLength = first.length + rest.length;
        String[] result = Arrays.copyOf(first, totalLength);
        int offset = first.length;
        int x = 0;
        for (int i = offset; i < totalLength; i++) {
            result[i] = rest[x++];/*  w  ww. j av a 2  s. c o  m*/
        }
        return result;
    }
    public static String[] concatAll(String[] first, String[]... rest) {
        int totalLength = first.length;
        for (String[] array : rest) {
            totalLength += array.length;
        }
        String[] result = Arrays.copyOf(first, totalLength);
        int offset = first.length;
        for (String[] array : rest) {
            System.arraycopy(array, 0, result, offset, array.length);
            offset += array.length;
        }
        return result;
    }

}

Related Tutorials