Here you can find the source of listToCommas(List
Parameter | Description |
---|---|
string | The string to insert commas in. |
public static String listToCommas(List<String> list)
//package com.java2s; //License from project: Open Source License import java.util.List; public class Main { /**/*from w w w .j av a 2s. c om*/ * Inserts a commas between each word in the given string with * StringBuilder. * * @param string * The string to insert commas in. * @return New string with commas. */ public static String listToCommas(List<String> list) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < list.size(); i++) { String string = list.get(i); if ((i + 1) == list.size()) { builder.append(string); } else builder.append(string + ", "); } return builder.toString().trim(); } }