Java String from List stringListString(List list)

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

Description

Static method to generate a list representation for an ArrayList of Strings S1,...,Sn

License

Open Source License

Parameter

Parameter Description
list A list of Strings

Return

A String consisting of the original list of strings concatenated and separated by commas, and enclosed by square brackets i.e. '[S1,S2,...,Sn]'

Declaration

public static String stringListString(List<String> list) 

Method Source Code


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

import java.util.List;

public class Main {
    /**/* w w w. j a  v a 2 s . c  o  m*/
     * Static method to generate a list representation for an ArrayList of Strings S1,...,Sn
     * 
     * @param list A list of Strings
     * @return A String consisting of the original list of strings concatenated and separated by
     *         commas, and enclosed by square brackets i.e. '[S1,S2,...,Sn]'
     */
    public static String stringListString(List<String> list) {

        String result = "[";
        for (int i = 0; i < list.size() - 1; i++) {
            result += list.get(i) + ",";
        }

        if (list.size() > 0) {
            // get the generated word for the last target position
            result += list.get(list.size() - 1);
        }

        result += "]";

        return result;

    }
}

Related

  1. stringifyList(List items)
  2. stringList(String prefix, String suffix, String separator, Object... objects)
  3. stringList2String(final String suffix, final List list)
  4. stringList2String(List list, String separator)
  5. stringListEquals(List left, List right)
  6. stringListToArray(final List list)
  7. stringListToArray(List list)
  8. stringListToArray(List params)
  9. stringListToString(final List l, final String separator)