Here you can find the source of join(String _delimiter, List
Parameter | Description |
---|---|
_delimiter | delimiting string |
_strings | strings to join |
public static String join(String _delimiter, List<String> _strings)
//package com.java2s; //License from project: Open Source License import java.util.Arrays; import java.util.List; public class Main { /**/* w w w . j av a 2 s.c o m*/ * Combines the Strings in _string using _delimiter. * @param _delimiter delimiting string * @param _strings strings to join * @return null if _strings is null, concatenated string otherwise */ public static String join(String _delimiter, List<String> _strings) { if (_strings == null) { return null; } if (_delimiter == null) { _delimiter = ""; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < _strings.size(); i++) { sb.append(_strings.get(i)); if (i < _strings.size() - 1) { // only append delimiter if this is not the last token sb.append(_delimiter); } } return sb.toString(); } /** * Combines the Strings in _string using _delimiter. * @param _delimiter delimiting string * @param _strings string to join * @return null if _strings is null, concatenated string otherwise */ public static String join(String _delimiter, String[] _strings) { return join(_delimiter, Arrays.asList(_strings)); } }