Java List Join join(List values, String delimiter)

Here you can find the source of join(List values, String delimiter)

Description

Join a given List of String s, separated by a given delimiter.

License

Open Source License

Parameter

Parameter Description
values the List of String s to join.
delimiter the delimiter

Return

the joined

Declaration

public static String join(List<String> values, String delimiter) 

Method Source Code


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

import java.util.List;

public class Main {
    /**//from   w  ww  .j av a2  s  .  c  o  m
     * Join a given {@link List} of {@link String}s, separated by a given delimiter.
     *
     * @param values    the {@link List} of {@link String}s to join.
     * @param delimiter the delimiter
     * @return the joined {@link String}
     */
    public static String join(List<String> values, String delimiter) {
        StringBuilder sb = new StringBuilder();
        if (values != null && !values.isEmpty()) {
            sb.append(values.get(0));
            for (int i = 1; i < values.size(); i++) {
                sb.append(delimiter);
                sb.append(values.get(i));
            }
        }
        return sb.toString();
    }
}

Related

  1. join(List strList, String sep)
  2. join(List tokens, String sep)
  3. join(List tokens, String separator)
  4. join(List tokens, String separator)
  5. join(List values)
  6. join(List values, String string)
  7. join(List words, String separator)
  8. join(List entries, String separator)
  9. join(List list, String delim)