Java List Join join(List list, String separator)

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

Description

Joins string representations of all objects from list into one String Elements are converted to strings as by String.valueOf(object)

License

Open Source License

Parameter

Parameter Description
list List of objects whose string representation to be joined
separator The value to be set between neighboring objects representations

Return

Joined String

Declaration

public static String join(List list, String separator) 

Method Source Code


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

import java.util.List;

public class Main {
    /**/*from  w  w w . j  a v a2s  .  c  o m*/
     * Joins string representations of all objects from list into one String
     * Elements are converted to strings as by  <tt>String.valueOf(object)</tt>
     *
     * @param list List of objects whose string representation to be joined
     * @param separator The value to be set between neighboring objects representations
     * @return Joined String
     */
    public static String join(List list, String separator) {
        StringBuilder str = new StringBuilder();
        for (Object item : list) {
            str.append(String.valueOf(item)).append(separator);
        }
        return str.substring(0, str.length() - separator.length());
    }
}

Related

  1. join(List list, char separator)
  2. join(List list, String delim)
  3. join(List list, String delimiter)
  4. join(List list, String flag)
  5. join(List list, String separator)
  6. join(List objects)
  7. join(List objects, String joiner)
  8. join(List strings, String delimiter)
  9. join(List vec, String separator)