Java Collection Join joinTo(Collection data, String sep, StringBuilder sb)

Here you can find the source of joinTo(Collection data, String sep, StringBuilder sb)

Description

join To

License

Apache License

Declaration

public static void joinTo(Collection<?> data, String sep, StringBuilder sb) 

Method Source Code

//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;
    }
}

Related

  1. joinStrings(Collection strings)
  2. joinStrings(Collection names)
  3. joinStrings(Collection strings)
  4. joinStrings(String delim, Collection strs)
  5. joinStringValues(Collection values)
  6. joinTogether(Collection items, String delim)
  7. joinToStringBuilder(Collection collection, String separator)
  8. joinValues(Collection values, String separator)
  9. roundjoin(Collection s, String delimiter)

  10. HOME | Copyright © www.java2s.com 2016