Java Array Combine combineLines(String[] lines)

Here you can find the source of combineLines(String[] lines)

Description

Combine the lines into a single string, using the new line character as the delimiter.

License

Apache License

Parameter

Parameter Description
lines the lines to be combined

Return

the combined lines, or an empty string if there are no lines

Declaration

public static String combineLines(String[] lines) 

Method Source Code

//package com.java2s;
/*//from w w w .  j  av  a2 s .co  m
 * ModeShape (http://www.modeshape.org)
 *
 * 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.
 */

public class Main {
    /**
     * Combine the lines into a single string, using the new line character as the delimiter. This is compatible with
     * {@link #splitLines(String)}.
     * 
     * @param lines the lines to be combined
     * @return the combined lines, or an empty string if there are no lines
     */
    public static String combineLines(String[] lines) {
        return combineLines(lines, '\n');
    }

    /**
     * Combine the lines into a single string, using the supplied separator as the delimiter.
     * 
     * @param lines the lines to be combined
     * @param separator the separator character
     * @return the combined lines, or an empty string if there are no lines
     */
    public static String combineLines(String[] lines, char separator) {
        if (lines == null || lines.length == 0)
            return "";
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i != lines.length; ++i) {
            String line = lines[i];
            if (i != 0)
                sb.append(separator);
            sb.append(line);
        }
        return sb.toString();
    }
}

Related

  1. combineChannels(int[][] a, int[][] r, int[][] g, int[][] b, int[][] pixels)
  2. combineChunksToByteArray(byte chunks[][])
  3. combineComponent(float[] partsComponent, float[] partsAlpha, int partsN)
  4. combineIndices(String[] in, String delimiter, int i, int j)
  5. combineIntArrays(int[] A, int[] B)