Java List Print printList(List list)

Here you can find the source of printList(List list)

Description

print List

License

Apache License

Declaration

public static <T> String printList(List<T> list) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.List;

public class Main {
    public static <T> String printList(List<T> list) {
        return printList(list, "[", "]", ", ");
    }/*from   w w  w.j  a  va2s .  c o  m*/

    public static <T> String printList(List<T> list, String prefix, String postfix, String separator) {
        StringBuilder sb = new StringBuilder(prefix);

        for (T t : list) {
            sb.append(t).append(separator);
        }
        if (sb.toString().endsWith(separator))
            return sb.toString().substring(0, sb.length() - separator.length()) + postfix;

        return sb.append(postfix).toString();
    }
}

Related

  1. printList(List list, String filename)
  2. printList(List list)
  3. printList(List> list)
  4. printList(List truthTableHeader)
  5. printList(List list)
  6. printListPair(List list)
  7. printListStrings(List list, String listDescription)
  8. printListV(List l)
  9. printListWithDelimiter(Collection list, String delimiter)