Java List to String listToString(List list, String sep)

Here you can find the source of listToString(List list, String sep)

Description

list To String

License

Apache License

Declaration

public static <T> String listToString(List<T> list, String sep) 

Method Source Code


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

import java.util.List;

public class Main {
    public static <T> String listToString(List<T> list, String sep) {
        if (list == null || list.isEmpty())
            return null;
        int size = list.size();
        StringBuilder sb = new StringBuilder();
        int count = 0;
        for (T str : list) {
            sb.append(str.toString());//www  .j  av a2s .c om
            if (count < size - 1)
                sb.append(sep);
            ++count;
        }
        return sb.toString();
    }
}

Related

  1. listToString(List lines)
  2. listToString(List list)
  3. listToString(List list)
  4. listToString(List list)
  5. listToString(List list, String prefix, String delimiter, String suffix)
  6. listToString(String itemName, List list)
  7. toString(final List list)
  8. toString(final List list, final String separtor)
  9. toString(final List list)