Join two string value by delimiter - Android java.lang

Android examples for java.lang:String Join

Description

Join two string value by delimiter

Demo Code

import android.text.TextUtils;
import java.util.ArrayList;
import java.util.List;

public class Main{

    public static String join(String delimiter, String[] strings) {

        if (strings.length == 0) {
            return "";
        }//from  w ww .  j a v a 2  s.c  o m

        StringBuilder stringBuilder = new StringBuilder();
        for (String str : strings) {
            stringBuilder.append(" ").append(str);
        }

        return stringBuilder.substring(1);
    }
    public static String join(int[] arr, String delimiter) {

        if (arr.length == 0) {
            return "";
        }

        StringBuilder sb = new StringBuilder();

        for (int i : arr) {
            sb.append(delimiter).append(Integer.toString(i));
        }

        return sb.substring(delimiter.length());

    }

}

Related Tutorials