Java List to String listToString(List list)

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

Description

list To String

License

Open Source License

Declaration

public static <E> String listToString(List<E> list) 

Method Source Code

//package com.java2s;
/*//from   w w  w . j  a  va2s. c o m
Copyright (c) Microsoft Open Technologies, Inc.
All Rights Reserved
See License.txt in the project root for license information.
*/

import java.util.List;

public class Main {
    public static <E> String listToString(List<E> list) {
        return arrayToString(list.toArray());
    }

    public static String arrayToString(Object[] arr) {
        if (arr == null) {
            return "<<NULL>>";
        } else {
            StringBuilder sb = new StringBuilder();
            sb.append("[");

            for (int i = 0; i < arr.length; i++) {
                Object elem = arr[i];
                sb.append(elem.toString());

                if (i != arr.length - 1) {
                    sb.append(", ");
                }
            }

            sb.append("]");

            return sb.toString();
        }
    }
}

Related

  1. listToString(List l, String sep)
  2. listToString(List list)
  3. listToString(List list)
  4. listToString(List list, String separator, String prefix, String suffix)
  5. listToString(List list, String seperator)
  6. listToString(List list)
  7. listToString(List list, String operator)
  8. listToString(List value)
  9. listToString(List args)

  10. HOME | Copyright © www.java2s.com 2016