Here you can find the source of combine(List
public static String combine(List<String> tokens, String separator)
//package com.java2s; //License from project: Apache License import java.util.List; import java.util.Set; public class Main { public static String combine(List<String> tokens, String separator) { StringBuffer sb = new StringBuffer(); boolean isFirst = true; for (String token : tokens) { if (isFirst) isFirst = false;// ww w . j a v a 2 s .c om else sb.append(separator); sb.append(token); } return sb.toString(); } public static String combine(Set<String> tokens, String separator) { StringBuffer sb = new StringBuffer(); boolean isFirst = true; for (String token : tokens) { if (isFirst) isFirst = false; else sb.append(separator); sb.append(token); } return sb.toString(); } public static String combine(String[] tokens, String separator, String nullvalue) { if (tokens == null || tokens.length == 0) return ""; StringBuffer sb = new StringBuffer(); for (int i = 0; i < tokens.length; i++) { if (tokens[i] == null) { sb.append(nullvalue); } else { sb.append(tokens[i]); } sb.append(separator); } return sb.substring(0, sb.length() - separator.length()); } public static String combine(String[] tokens, String separator) { StringBuffer sb = new StringBuffer(); boolean isFirst = true; for (String token : tokens) { if (isFirst) isFirst = false; else sb.append(separator); sb.append(token); } return sb.toString(); } }