Java List Join joinString(List objs, String separator)

Here you can find the source of joinString(List objs, String separator)

Description

Create a string for a list of objects, with a specified separator, e.g.

License

Open Source License

Declaration

public static String joinString(List<?> objs, String separator) 

Method Source Code

//package com.java2s;
//   it under the terms of the GNU General Public License as published by

import java.util.List;

public class Main {
    /**/*from w  ww . j a v a  2s.co  m*/
     * Create a string for a list of objects, with a specified separator,
     * e.g. ["a","b","c"], "," -&gt; "a,b,c"
     */
    public static String joinString(List<?> objs, String separator) {
        String s = "";
        boolean first = true;
        for (Object obj : objs) {
            if (first) {
                first = false;
            } else {
                s += separator;
            }
            s += obj.toString();
        }
        return s;
    }

    /**
     * Create a string for an array of objects, with a specified separator,
     * e.g. ["a","b","c"], "," -&gt; "a,b,c"
     */
    public static String joinString(Object[] objs, String separator) {
        String s = "";
        boolean first = true;
        for (Object obj : objs) {
            if (first) {
                first = false;
            } else {
                s += separator;
            }
            s += obj.toString();
        }
        return s;
    }
}

Related

  1. joinRecords(List first, List second, String key)
  2. joinRelativePath(List components)
  3. joinSegments(List segments, int startIndex, int endIndex)
  4. joinString(java.util.List values, String delimiter)
  5. joinString(List array, String symbol)
  6. joinString(List val, String delim)
  7. joinStringList(String delimiter, List stringList)
  8. joinStrings(Iterable list)
  9. joinStrings(List aList, String aString)