@Test public void testJoin() { final ArrayList<String> list = new ArrayList<>(); assertEquals("", Collection.join(list, ",")); list.add("test1"); assertEquals("test1", Collection.join(list, ",")); list.add("test2"); assertEquals("test1,test2", Collection.join(list, ",")); assertEquals("test1:sep:test2", Collection.join(list, ":sep:")); assertEquals("test1test2", Collection.join(list, "")); }
public static <T> String join(List<T> list, String separator, Function<T, String> function) { String result = ""; for (int i = 0; i < list.size(); i++) { result += function.apply(list.get(i)).trim(); if (i + 1 < list.size()) { result += separator; } } return result; }
Collection { public static <T> String join(List<T> list, String separator, Function<T, String> function) { String result = ""; for (int i = 0; i < list.size(); i++) { result += function.apply(list.get(i)).trim(); if (i + 1 < list.size()) { result += separator; } } return result; } }
Collection { public static <T> String join(List<T> list, String separator, Function<T, String> function) { String result = ""; for (int i = 0; i < list.size(); i++) { result += function.apply(list.get(i)).trim(); if (i + 1 < list.size()) { result += separator; } } return result; } private  Collection(); }
Collection { public static <T> String join(List<T> list, String separator, Function<T, String> function) { String result = ""; for (int i = 0; i < list.size(); i++) { result += function.apply(list.get(i)).trim(); if (i + 1 < list.size()) { result += separator; } } return result; } private  Collection(); static String[] tail(String[] args); @SafeVarargs static T[] create(T... args); static String join(List<T> list, String separator, Function<T, String> function); static String join(List<String> list, String separator); }
Collection { public static <T> String join(List<T> list, String separator, Function<T, String> function) { String result = ""; for (int i = 0; i < list.size(); i++) { result += function.apply(list.get(i)).trim(); if (i + 1 < list.size()) { result += separator; } } return result; } private  Collection(); static String[] tail(String[] args); @SafeVarargs static T[] create(T... args); static String join(List<T> list, String separator, Function<T, String> function); static String join(List<String> list, String separator);  }