Java Comma Separated List commalist(List l)

Here you can find the source of commalist(List l)

Description

commalist

License

Open Source License

Declaration

public static String commalist(List l) 

Method Source Code

//package com.java2s;

import java.util.Iterator;

import java.util.List;

public class Main {
    public static final String COMMA = ",";

    public static String commalist(List l) {
        StringBuffer buf = new StringBuffer();
        commalist(l, buf);//from w  ww.j a  v  a 2 s .  c  o m
        return buf.toString();
    }

    public static void commalist(List l, StringBuffer buf) {
        Iterator i = l.iterator();
        while (i.hasNext()) {
            buf.append(i.next().toString());
            if (i.hasNext())
                buf.append(", ");
        }
    }

    public static String commalist(Object[] o) {
        StringBuffer buf = new StringBuffer();
        commalist(o, buf);
        return buf.toString();
    }

    public static void commalist(Object[] o, StringBuffer buf) {
        for (int cntr = 0; cntr < o.length; cntr++) {
            if (cntr > 0)
                buf.append(", ");
            buf.append(o[cntr].toString());
        }
    }

    public static void commalist(Iterator i, StringBuffer buf) {
        for (int cntr = 0; i.hasNext(); cntr++) {
            if (cntr > 0)
                buf.append(", ");
            buf.append(i.next().toString());
        }
    }

    public static String commalist(Object o1, Object o2) {
        return o1 + COMMA + o2;
    }

    public static String commalist(Object o1, Object o2, Object o3) {
        return o1 + COMMA + o2 + COMMA + o3;
    }

    public static String commalist(Object o1, Object o2, Object o3,
            Object o4) {
        return o1 + COMMA + o2 + COMMA + o3 + COMMA + o4;
    }
}

Related

  1. commaDelimitedListToStringArray(String str)
  2. commaDelimitedListToStringArray(String str)
  3. commaDelimitedListToStringArray(String str)
  4. commaDelimitedStringToList(String str)
  5. commaDelimitedToList(String commaDelimited)
  6. commalist(List l)
  7. commandToString(List args)
  8. commaSeparate(List a_list)
  9. commaSeparatedClassNames(final List objects)

    HOME | Copyright © www.java2s.com 2016