Java List Join join(List lst, String separator)

Here you can find the source of join(List lst, String separator)

Description

Joining by separator after each 'not last' value

License

Open Source License

Parameter

Parameter Description
lst list for joining
separator separator string

Return

joined string

Declaration

public static String join(List<String> lst, String separator) 

Method Source Code

//package com.java2s;

import java.util.*;

public class Main {
    /**//from  ww  w .  jav a  2s. c  om
     * Joining by separator after each 'not last' value
     *
     * @param lst list for joining
     * @param separator separator string
     * @return joined string
     */
    public static String join(List<String> lst, String separator) {
        if (lst == null)
            return "";
        StringBuilder str = new StringBuilder();
        Iterator<String> iter = lst.iterator();
        while (iter.hasNext()) {
            str.append(iter.next());
            if (iter.hasNext()) {
                str.append(separator);
            }
        }
        return str.toString();
    }
}

Related

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