Here you can find the source of concatListToString(List
public static String concatListToString(List<String> suggestedList)
//package com.java2s; //License from project: Open Source License import java.util.List; public class Main { public static final String STRING_SPACER = " | "; public static String concatListToString(List<String> suggestedList) { String suggestedWords = new String(); for (int i = 0; i < suggestedList.size(); i++) { String word = suggestedList.get(i); suggestedWords = addWord(suggestedWords, word); suggestedWords = trimIfLastIndex(suggestedList, suggestedWords, i); }//from w w w . j av a 2 s . c o m return suggestedWords; } private static String addWord(String suggestedWords, String word) { suggestedWords = suggestedWords + word + STRING_SPACER; return suggestedWords; } private static String trimIfLastIndex(List<String> suggestedList, String suggestedWords, int i) { if (isLastIndex(suggestedList, i)) { suggestedWords = trimSuggestions(suggestedWords); } return suggestedWords; } private static boolean isLastIndex(List<String> suggestedList, int i) { return i == suggestedList.size() - 1; } private static String trimSuggestions(String suggestedWords) { int index = suggestedWords.lastIndexOf(STRING_SPACER); return suggestedWords.substring(0, index); } }