Java Utililty Methods Comma Separated List

List of utility methods to do Comma Separated List

Description

The list of methods to do Comma Separated List are organized into topic(s).

Method

StringlistToCommandLine(List commands)
list To Command Line
String arguments = "";
for (String command : commands) {
    arguments += command;
    arguments += " ";
if (arguments.length() > 0)
    arguments = arguments.substring(0, arguments.length() - 1);
return arguments;
...
StringlistToCommas(List list)
Inserts a commas between each word in the given string with StringBuilder.
StringBuilder builder = new StringBuilder();
for (int i = 0; i < list.size(); i++) {
    String string = list.get(i);
    if ((i + 1) == list.size()) {
        builder.append(string);
    } else
        builder.append(string + ", ");
return builder.toString().trim();
StringlistToCommaSep(List strings)
list To Comma Sep
if (strings.isEmpty())
    return "&bNone";
StringBuilder sb = new StringBuilder();
strings.forEach(s -> sb.append("&3").append(s).append("&7, "));
return sb.delete(sb.length() - 2, sb.length()).toString();
StringlistToCommaSeparatedList(String prefix, List stringList)
list To Comma Separated List
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(prefix);
for (int i = 0; i < stringList.size(); i++) {
    stringBuilder.append(stringList.get(i));
    if ((i + 1) < stringList.size())
        stringBuilder.append(",");
return stringBuilder.toString();
...
StringlistToCommaSeparatedString(List list)
list To Comma Separated String
if (list == null) {
    return null;
StringBuffer result = new StringBuffer();
for (int i = 0; i < list.size(); i++) {
    result.append(list.get(i) + (i == list.size() - 1 ? "" : ", "));
return result.toString();
...
StringlistToString(List list, boolean doCommas)
list To String
StringBuilder sb = new StringBuilder();
for (String str : list) {
    if (sb.length() > 0) {
        if (doCommas) {
            sb.append(",");
        sb.append(" ");
    sb.append(str);
return sb.toString();
ArrayListloadListFromStrings(final String commaDelimitedStrings, final boolean sortList)
Converts a string containing a comma-delimited list of values into a List containing those values.
return loadListFromStrings(null, commaDelimitedStrings, sortList);
voidmoveClasspathArgToEnvironmentVariable(List commandArgs, ProcessBuilder pb)
move Classpath Arg To Environment Variable
int cpFlagIndex = commandArgs.indexOf("-cp");
if (cpFlagIndex == -1) {
    cpFlagIndex = commandArgs.indexOf("-classpath");
if (cpFlagIndex > -1 && cpFlagIndex < commandArgs.size() - 1) {
    Map<String, String> env = pb.environment();
    String classpath = commandArgs.get(cpFlagIndex + 1);
    env.put("CLASSPATH", classpath);
...
ListparseCommaList(String nameCommaList)
Parses a comma-separated list.
if (nameCommaList.equals("")) {
    return Collections.emptyList();
if (nameCommaList.endsWith(",")) {
    final String zzz = "zzz";
    final List<String> list = parseCommaList(nameCommaList + zzz);
    String last = list.get(list.size() - 1);
    if (last.equals(zzz)) {
...
voidparseRsfCommands(List rsfLines, List addItemCommands, List appendEntryCommands)
parse Rsf Commands
rsfLines.stream().forEach(command -> {
    if (command.startsWith("add-item")) {
        addItemCommands.add(command);
    } else if (command.startsWith("append-entry")) {
        appendEntryCommands.add(command);
});