Java List Join join(List list, String sep)

Here you can find the source of join(List list, String sep)

Description

This function is used to join all elements from a List list of String strings in only one String .

License

Open Source License

Parameter

Parameter Description
list List < String > - The list of <code>String</code> to concatenate
sep String - The separator to add between each elements in the result

Return

- The list concatenate in a String

Declaration

public static String join(List<String> list, String sep) 

Method Source Code


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

import java.util.List;

public class Main {
    /**/*from  w  ww . j a v a 2s .c  o m*/
     * This function is used to join all elements from a {@link List list} of
     * {@link String strings} in only one {@link String}. All elements of the
     * list are separated with the given separator.
     * 
     * @param list
     *            {@link List}<{@link String}> - The list of <code>String</code>
     *            to concatenate
     * @param sep
     *            {@link String} - The separator to add between each elements in
     *            the result
     * @return {@link String} - The list concatenate in a String
     */
    public static String join(List<String> list, String sep) {
        if (list.size() == 1) {
            return list.remove(0);
        } else {
            return list.remove(0) + sep + join(list, sep);
        }
    }
}

Related

  1. join(List list, String delim)
  2. join(List list, String delim)
  3. join(List list, String delimiter)
  4. join(List list, String delimiter)
  5. join(List list, String delimiter)
  6. join(List list, String separator)
  7. join(List list, String separator)
  8. join(List list1, List list2)
  9. join(List list1, List list2)