Here you can find the source of joinTo(Collection> data, String sep, StringBuilder sb)
public static void joinTo(Collection<?> data, String sep, StringBuilder sb)
//package com.java2s; /*//w w w . j a v a 2 s . c o m * JEF - Copyright 2009-2010 Jiyi (mr.jiyi@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.Collection; import java.util.Iterator; public class Main { public static void joinTo(Collection<?> data, String sep, StringBuilder sb) { if (data == null || data.isEmpty()) return; Iterator<?> iterator = data.iterator(); sb.append(String.valueOf(iterator.next())); while (iterator.hasNext()) { Object obj = iterator.next(); sb.append(sep).append(String.valueOf(obj)); } } public static void joinTo(Object[] data, char sep, StringBuilder sb) { if (data == null || data.length == 0) return; sb.append(String.valueOf(data[0])); for (int i = 1; i < data.length; i++) { sb.append(sep).append(String.valueOf(data[i])); } } public static boolean isEmpty(Object value) { if (value == null) return true; if (value instanceof CharSequence) { return ((CharSequence) value).length() == 0; } return false; } }