Here you can find the source of join(String[] tokens, String separator)
Parameter | Description |
---|---|
tokens | the string tokens |
separator | the separator to use between all tokens |
public static String join(String[] tokens, String separator)
//package com.java2s; //License from project: LGPL import java.util.List; public class Main { /**/*from w w w.j a v a 2 s . co m*/ * Join all tokens dividing by a separator * * @param tokens * the string tokens * @param separator * the separator to use between all tokens * @return a string will all tokens separated by the defined separator */ public static String join(String[] tokens, String separator) { StringBuilder history = new StringBuilder(); if (tokens.length > 0) { history.append(tokens[0]); } for (int i = 1; i < tokens.length; i++) { history.append(separator).append(tokens[i]); } return history.toString(); } public static String join(List<String> tokens, String separator) { StringBuilder history = new StringBuilder(); if (!tokens.isEmpty()) { history.append(tokens.get(0)); } for (int i = 1; i < tokens.size(); i++) { history.append(separator).append(tokens.get(i)); } return history.toString(); } }