Java List Join joinList(List list, String separator)

Here you can find the source of joinList(List list, String separator)

Description

join List

License

LGPL

Declaration

@SuppressWarnings("rawtypes")
public static String joinList(List list, String separator) 

Method Source Code

//package com.java2s;
/**/*w  w  w .  ja  va2 s . c  o  m*/
 * Converts a line of text into an array of lower case words using a
 * BreakIterator.wordInstance(). <p>
 *
 * This method is under the Jive Open Source Software License and was
 * written by Mark Imbriaco.
 *
 * @param text a String of text to convert into an array of words
 * @return text broken up into an array of words.
 */

import java.util.List;
import java.util.Iterator;

public class Main {

    @SuppressWarnings("rawtypes")
    public static String joinList(List list, String separator) {
        String rtVal = "";
        if (separator == null)
            separator = ",";

        Iterator it = list.iterator();
        while (it.hasNext()) {
            rtVal += (String) it.next() + separator;
        }

        if (rtVal.length() > 1)
            return rtVal.substring(0, rtVal.length() - 1);
        else
            return rtVal;

    }

    @SuppressWarnings("rawtypes")
    public static String joinList(List list) {
        return joinList(list, null);
    }

    public static String substring(String str, int len) {
        len = len * 2;
        StringBuffer sb = new StringBuffer();
        int counter = 0;
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (c < 255) {
                counter++;
            } else {
                counter = counter + 2;
            }
            if (counter > len) {
                break;
            }
            sb.append(c);
        }
        return sb.toString();
    }
}

Related

  1. joinLines(List lines)
  2. joinLinesWithImplicitFinalLine(final List lines)
  3. joinList(final List list)
  4. joinList(final List list, final String sep)
  5. joinList(List list, String separator)
  6. joinList(List items)
  7. joinList(List list, String glue)
  8. joinList(List list, String separator)
  9. joinList(List parts, String sep)