join CharSequence with array of tokens - Android java.lang

Android examples for java.lang:String Join

Description

join CharSequence with array of tokens

Demo Code

import android.text.TextUtils;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main{

    /**/* w w w. j  a va 2s. c om*/
     * Returns a string containing the tokens joined by delimiters.
     * @param tokens an array objects to be joined.
     */
    public static String join(CharSequence delimiter, int[] tokens) {
        StringBuilder sb = new StringBuilder();
        boolean firstTime = true;
        for (Object token : tokens) {
            if (firstTime) {
                firstTime = false;
            } else {
                sb.append(delimiter);
            }
            sb.append(token);
        }
        return sb.toString();
    }

}

Related Tutorials