Java List Concatenate concatLines(List lines)

Here you can find the source of concatLines(List lines)

Description

Returns a concatenated string consisting of the given lines seperated by a new line character \n.

License

Apache License

Declaration

public static String concatLines(List<String> lines) 

Method Source Code

//package com.java2s;
/*//from  w w  w .  j a v  a2s.c om
 * Copyright (C) 2014 Markus Junginger, greenrobot (http://greenrobot.de)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.List;

public class Main {
    /**
     * Returns a concatenated string consisting of the given lines seperated by a new line character \n. The last line
     * does not have a \n at the end.
     */
    public static String concatLines(List<String> lines) {
        StringBuilder builder = new StringBuilder();
        int countMinus1 = lines.size() - 1;
        for (int i = 0; i < countMinus1; i++) {
            builder.append(lines.get(i)).append('\n');
        }
        if (!lines.isEmpty()) {
            builder.append(lines.get(countMinus1));
        }
        return builder.toString();
    }
}

Related

  1. concatenateStrings(List strings, String separator)
  2. concatenateUniqueLists(List first, List second)
  3. concatGenericList(List list, String delimiter)
  4. concatinateStrings(List strList, String delim)
  5. concatIntegersToRanges( List damages)
  6. concatLines(List lines)
  7. concatLineSeparated(List discountCommentCauseList)
  8. concatList(List list)
  9. concatList(List... array)