Here you can find the source of concatAndJoin(String sep, List
Parameter | Description |
---|---|
sep | separator between list elements |
data | list of strings |
prefix | prefix concatenated before each element in the list |
suffix | suffix concatenated after each element in the list |
public static String concatAndJoin(String sep, List<String> data, String prefix, String suffix)
//package com.java2s; //License from project: Open Source License import java.util.List; public class Main { /**/*from ww w . ja va2 s .c o m*/ * Concat a prefix and suffix to each element in a list, and join with a separator. * For example, turn the list a b c into {a};{b};{c} * * Equivalent to the following groovy code: * * <pre>data.collect{ prefix + it + suffix }.join(sep)</pre> * * @param sep separator between list elements * @param data list of strings * @param prefix prefix concatenated before each element in the list * @param suffix suffix concatenated after each element in the list */ public static String concatAndJoin(String sep, List<String> data, String prefix, String suffix) { StringBuilder builder = new StringBuilder(); boolean first = true; for (String str : data) { if (first) { first = false; } else { builder.append(sep); } builder.append(prefix); builder.append(str); builder.append(suffix); } return builder.toString(); } }