Java List Join join(List strings, String join)

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

Description

Join a list of strings with the given joining string.

License

Open Source License

Parameter

Parameter Description
strings The strings to join.
join The string to join them with, or null if no string is to be used.

Return

The string consisting of the strings joined together.

Declaration

public static String join(List<String> strings, String join) 

Method Source Code


//package com.java2s;

import java.util.List;

public class Main {
    /**//w  ww .ja v  a  2s  .  c o m
     * Join a list of strings with the given joining string.
     * 
     * @param strings The strings to join.
     * @param join The string to join them with, or null if no string is to be used.
     * @return The string consisting of the strings joined together.
     */
    public static String join(List<String> strings, String join) {
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < strings.size(); ++i) {
            String entry = strings.get(i);
            buffer.append(entry);
            if (join != null) {
                if (i < (strings.size() - 1)) {
                    buffer.append(join);
                }
            }
        }
        return buffer.toString();
    }
}

Related

  1. join(List strings)
  2. join(List strings)
  3. join(List strings)
  4. join(List strings, String delim)
  5. join(List strings, String delimiter)
  6. join(List strings, String joiner)
  7. join(List strings, String sep)
  8. join(List strings, String separator)
  9. join(List strings, String separator)