Here you can find the source of flatten(Object[] lines, String sep)
Parameter | Description |
---|---|
lines | the lines to flatten |
sep | the separator |
public static String flatten(Object[] lines, String sep)
//package com.java2s; /*// w w w .j a v a 2s . com * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.util.List; public class Main { /** * Flattens the list into a single, long string. The separator string gets * added between the objects, but not after the last one. * * @param lines the lines to flatten * @param sep the separator * @return the generated string */ public static String flatten(List lines, String sep) { return flatten(lines.toArray(new Object[lines.size()]), sep); } /** * Flattens the array into a single, long string. The separator string gets * added between the objects, but not after the last one. Uses the "toString()" * method of the objects to turn them into a string. * * @param lines the lines to flatten * @param sep the separator * @return the generated string */ public static String flatten(Object[] lines, String sep) { StringBuilder result; int i; result = new StringBuilder(); for (i = 0; i < lines.length; i++) { if (i > 0) result.append(sep); result.append(lines[i].toString()); } return result.toString(); } }