Java List to String listToString(List l)

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

Description

list To String

License

Open Source License

Declaration

public static String listToString(List l) 

Method Source Code


//package com.java2s;
import java.util.*;

public class Main {
    public static String listToString(List l) {
        return listToString(l, ", ", "(", ")");
    }//from  ww w.j  ava 2 s.c o  m

    public static String listToString(List l, String delimiter, String beginList, String endList) {
        StringBuffer sb = new StringBuffer();
        sb.append(beginList);

        // append first item
        Iterator i = l.iterator();
        if (i.hasNext()) {
            String item = (String) (i.next());
            sb.append(item);
        }

        // append the rest of items
        while (i.hasNext()) {
            String items = (String) (i.next());
            sb.append(delimiter + items);
        }

        sb.append(endList);

        return sb.toString();
    }
}

Related

  1. listToString(final List list)
  2. listToString(final List stringList)
  3. listToString(Iterable list)
  4. listToString(List a, String separator)
  5. listToString(List inList, String delimeter)
  6. listToString(List l)
  7. listToString(List list)
  8. listToString(List list)
  9. listToString(List list)