Java List to String listToString(List list, String header, String separator, String footer)

Here you can find the source of listToString(List list, String header, String separator, String footer)

Description

list To String

License

Open Source License

Parameter

Parameter Description
list The List to be represented as a String
header The String prepended to the String representation
separator The String separating each List element
footer The String appended to the String representation

Return

The String representation of the List

Declaration

public static String listToString(List<? extends Object> list, String header, String separator, String footer) 

Method Source Code


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

import java.util.List;

public class Main {
    /**// w ww.  jav  a2  s.  c o m
     *
     * @param list The List to be represented as a String
     * @param header The String prepended to the String representation
     * @param separator The String separating each List element
     * @param footer The String appended to the String representation
     *
     * @return The String representation of the List
     */
    public static String listToString(List<? extends Object> list, String header, String separator, String footer) {
        String delim = "";
        StringBuilder sb = new StringBuilder(header);

        for (int i = 0; i < list.size(); i++) {
            sb.append(delim).append("" + list.get(i));
            delim = separator;
        }

        return sb.append(footer).toString();
    }
}

Related

  1. listToString(List list, String glue)
  2. listToString(List list, String prefix, String suffix, String separator)
  3. listToString(List list)
  4. listToString(List list)
  5. listToString(List list, String delim)
  6. ListToString(List lista)
  7. listToString(List collection)
  8. listToString(List items)
  9. listToString(List l, String delim)