Java List Concatenate concatListToString(List suggestedList)

Here you can find the source of concatListToString(List suggestedList)

Description

concat List To String

License

Open Source License

Declaration

public static String concatListToString(List<String> suggestedList) 

Method Source Code

//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);
    }
}

Related

  1. concatLines(List lines)
  2. concatLineSeparated(List discountCommentCauseList)
  3. concatList(List list)
  4. concatList(List... array)
  5. concatList(List strings)
  6. concatName(String name, List names)
  7. concatNodeList(List list)
  8. concatPathTokens(String root, List tokens)
  9. concatRefs(List refs)