Java List to String toString(final List list)

Here you can find the source of toString(final List list)

Description

to String

License

Open Source License

Declaration

public static <E> String toString(final List<E> list) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    public static <E> String toString(final List<E> list) {
        return toString(list, "\t");
    }//from ww  w  . ja  v  a 2 s.c o m

    public static <E> String toString(final List<E> list, String separator) {
        StringBuilder sb = new StringBuilder();
        if (list != null && list.size() > 0) {
            for (int i = 0; i < list.size() - 1; i++) {
                if (list.get(i) != null) {
                    sb.append(list.get(i).toString()).append(separator);
                } else {
                    sb.append("null").append(separator);
                }
            }
            if (list.get(list.size() - 1) != null) {
                sb.append(list.get(list.size() - 1).toString());
            } else {
                sb.append("null");
            }
        }
        return sb.toString();
    }
}

Related

  1. listToString(List list, String prefix, String delimiter, String suffix)
  2. listToString(List list, String sep)
  3. listToString(String itemName, List list)
  4. toString(final List list)
  5. toString(final List list, final String separtor)
  6. toString(final List inMessages)
  7. toString(final List input)
  8. toString(final List list, char delimiter)
  9. toString(final Object[] list)