Java List to String listToStr(List lst)

Here you can find the source of listToStr(List lst)

Description

Return a string containing the comma-delimited string representation of the input list.

License

Apache License

Declaration

public static <E> String listToStr(List<E> lst) 

Method Source Code

//package com.java2s;
/**/* w w  w.  ja  va 2s .  c o  m*/
 * Licensed to Odiago, Inc. under one or more contributor license
 * agreements.  See the NOTICE.txt file distributed with this work for
 * additional information regarding copyright ownership.  Odiago, Inc.
 * licenses this file to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

import java.util.List;

public class Main {
    /** Return a string containing the comma-delimited string representation of the input list. */
    public static <E> String listToStr(List<E> lst) {
        StringBuilder sb = new StringBuilder();
        formatList(sb, lst);
        return sb.toString();
    }

    /** Format members of a list into a comma-delimited string builder. */
    public static <E> void formatList(StringBuilder sb, List<E> lst) {
        boolean first = true;
        for (E elem : lst) {
            if (!first) {
                sb.append(", ");
            }
            sb.append(elem.toString());
            first = false;
        }
    }
}

Related

  1. convertListToString(List strList)
  2. convertListToString(List valueList)
  3. convertListToStringWithSeparator( List myList, String separator)
  4. listToStr(Collection a, char sep)
  5. listToStr(Collection c, String delim)
  6. listToStr(List list)
  7. listToStr(List stringList)
  8. listToStrArray(List list)
  9. listToString (final List l)