Here you can find the source of combineLines(String[] lines)
Parameter | Description |
---|---|
lines | the lines to be combined |
public static String combineLines(String[] lines)
//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(); } }