Here you can find the source of join(String[] strings, String separator)
Parameter | Description |
---|---|
strings | a parameter |
separator | a parameter |
public static String join(String[] strings, String separator)
//package com.java2s; import java.util.Arrays; import java.util.List; public class Main { /**/*from w ww . ja va 2 s . c o m*/ * Join all strings into a new concatenated string. * @param strings * @param separator * @return concatenated string with separator in between elements. */ public static String join(String[] strings, String separator) { return join(Arrays.asList(strings), separator, false, false); } /** * Join all strings into a new concatenated string. * @param strings * @param separator * @param skipEmpty * @return concatenated string with separator in between elements. */ public static String join(String[] strings, String separator, boolean skipEmpty) { return join(Arrays.asList(strings), separator, skipEmpty, false); } /** * Join all strings into a new concatenated string. * @param strings * @param separator * @param skipEmpty * @param skipNull * @return concatenated string with separator in between elements. */ public static String join(String[] strings, String separator, boolean skipEmpty, boolean skipNull) { return join(Arrays.asList(strings), separator, skipEmpty, skipNull); } /** * Join all strings into a new concatenated string. * @param strings * @param separator * @return concatenated string with separator in between elements. */ public static String join(List<String> strings, String separator) { return join(strings, separator, false, false); } /** * Join all strings into a new concatenated string. * @param strings * @param separator * @param skipEmpty * @return concatenated string with separator in between elements. */ public static String join(List<String> strings, String separator, boolean skipEmpty) { return join(strings, separator, skipEmpty, false); } /** * Join all strings into a new concatenated string. * @param strings * @param separator * @param skipEmpty * @param skipNull * @return concatenated string with separator in between elements. */ public static String join(List<String> strings, String separator, boolean skipEmpty, boolean skipNull) { StringBuilder sb = new StringBuilder(); boolean isAfterFirst = false; for (String string : strings) { boolean isSkip = (skipNull && string == null) || (skipEmpty && string.isEmpty()); if (!isSkip) { if (isAfterFirst) { sb.append(separator); } sb.append(string); isAfterFirst = true; } } return sb.toString(); } }