Here you can find the source of join(List list, String separator)
Parameter | Description |
---|---|
list | List of objects whose string representation to be joined |
separator | The value to be set between neighboring objects representations |
public static String join(List list, String separator)
//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()); } }