Here you can find the source of join(final String[] values, final String delimiter)
Parameter | Description |
---|---|
values | - the string to concatenate |
delimiter | - delimiter to use between strings |
public static String join(final String[] values, final String delimiter)
//package com.java2s; //License from project: Apache License import java.util.List; public class Main { public static final int AVERAGE_STRING_LENGTH = 20; /**// ww w. ja v a 2 s .c o m * joins list of strings using a delimiter. * * @param values - the string to concatenate * @param delimiter - delimiter to use between strings * @return List of values delimeted by delimiter. */ public static String join(final String[] values, final String delimiter) { if (values == null) { return ""; } final StringBuilder result = new StringBuilder(values.length * AVERAGE_STRING_LENGTH); for (int i = 0; i < values.length; i++) { result.append(values[i]); if (i < values.length - 1) { result.append(delimiter); } } return result.toString(); } /** * joins list of strings using a delimiter. * * @param values - the string to concatenate * @param delimiter - delimiter to use between strings * @return List of values delimited by delimiter. */ public static String join(final List<String> values, final String delimiter) { if (values == null) { return ""; } final StringBuilder result = new StringBuilder(values.size() * AVERAGE_STRING_LENGTH); for (int i = 0; i < values.size(); i++) { result.append(values.get(i)); if (i < values.size() - 1) { result.append(delimiter); } } return result.toString(); } }