Here you can find the source of implode(String separator, String... data)
public static String implode(String separator, String... data)
//package com.java2s; //License from project: Open Source License public class Main { public static String implode(String separator, String... data) { StringBuilder sb = new StringBuilder(); boolean any = false; for (int i = 0; i < data.length; i++) { if (data[i] != null && !data[i].matches(" *")) { sb.append(data[i]);// w w w .ja va2 s .c o m any = true; if (i < data.length - 1 && data[i + 1] != null && !data[i + 1].matches(" *")) sb.append(separator); } } return any ? sb.toString() : null; } @SafeVarargs public static <E extends Enum<E>> String implode(String separator, E... data) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < data.length - 1; i++) { if (!data[i].toString().matches(" *")) { sb.append(data[i]); sb.append(separator); } } sb.append(data[data.length - 1].toString().trim()); return sb.toString(); } }