Java StringJoiner Usage listToString(List list)

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

Description

list To String

License

Apache License

Declaration

static <T> String listToString(List<T> list) 

Method Source Code

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

import java.util.List;

import java.util.StringJoiner;

public class Main {
    static <T> String listToString(List<T> list) {
        if (list == null || list.isEmpty())
            return null;
        StringJoiner joiner = new StringJoiner(",", "[", "]");
        for (Object o : list) {
            if (o == null)
                joiner.add("null");
            else//from ww  w  . j a v  a2s .  c  om
                joiner.add(o.toString());
        }
        return joiner.toString();
    }

    private static String toString(Object object) {
        if (object == null)
            return null;
        return String.valueOf(object);
    }
}

Related

  1. join(Collection data, String delimiter)
  2. join(final String left, final String right)
  3. join(String separator, Collection c)
  4. joinRepeating(String element, String delimiter, int times)
  5. joinToString(String sep, Iterable items)
  6. print(int[] a)
  7. split(String s)
  8. throwSafeguardError(String thisClassName, String thisMethodsName, String superClassName, String... namesOfMethodsWhoseDefaultImplementationUsesThisMethod)
  9. toCVS(Set buildRecordSetIds)