Java List Join join(List members, boolean quote)

Here you can find the source of join(List members, boolean quote)

Description

Helper to join a list of strings to a optionally quoted, comma separated string.

License

Open Source License

Parameter

Parameter Description
members the strings to join
quote whether to quote each string

Return

the single string containing a comma separated list of strings

Declaration

private static String join(List<String> members, boolean quote) 

Method Source Code


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

import java.util.List;

public class Main {
    /**//from  w  w w  .  ja va2  s  .c  om
     * Helper to join a list of strings to a optionally quoted, comma separated string.
     * 
     * @param members
     *            the strings to join
     * @param quote
     *            whether to quote each string
     * @return the single string containing a comma separated list of strings
     */
    private static String join(List<String> members, boolean quote) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < members.size(); ++i) {
            if (i != 0) {
                builder.append(",");
            }
            if (quote) {
                builder.append('"').append(members.get(i)).append('"');
            } else {
                builder.append(members.get(i));
            }
        }
        return builder.toString();
    }
}

Related

  1. join(List list, String separator)
  2. join(List list1, List list2)
  3. join(List list1, List list2)
  4. join(List lst, int start, int end)
  5. join(List lst, String separator)
  6. join(List p_sStrList, String p_sDelimiter)
  7. join(List parts, String separator)
  8. join(List paths)
  9. join(List s, String delim)