Here you can find the source of join(String sep, Collection> values)
Parameter | Description |
---|---|
sep | the separator |
values | collection of objects, null is converted to the empty string |
public static String join(String sep, Collection<?> values)
//package com.java2s; // License: GPL. For details, see LICENSE file. import java.util.Collection; public class Main { /**//from w w w .ja v a2 s. com * Joins a list of strings (or objects that can be converted to string via * Object.toString()) into a single string with fields separated by sep. * * @param sep * the separator * @param values * collection of objects, null is converted to the empty string * @return null if values is null. The joined string otherwise. */ public static String join(String sep, Collection<?> values) { if (sep == null) throw new IllegalArgumentException(); if (values == null) return null; if (values.isEmpty()) return ""; StringBuilder s = null; for (Object a : values) { if (a == null) { a = ""; } if (s != null) { s.append(sep).append(a.toString()); } else { s = new StringBuilder(a.toString()); } } return s.toString(); } }