Here you can find the source of join(Iterable extends Object> arr, String delimeter)
Parameter | Description |
---|---|
arr | The array to convert to a string. |
delimeter | A string that will separate each element in `arr'. |
public static String join(Iterable<? extends Object> arr, String delimeter)
//package com.java2s; /*// w w w. j a va2 s . co m * This file is part of the Raster Storage Archive (RSA). * * The RSA 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. * * The RSA 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 * the RSA. If not, see <http://www.gnu.org/licenses/>. * * Copyright 2013 CRCSI - Cooperative Research Centre for Spatial Information * http://www.crcsi.com.au/ */ import java.util.Arrays; public class Main { /** * Concatenate a list of values together as a string. * * @param arr The array to convert to a string. * @param delimeter A string that will separate each element in `arr'. * @return All elements of `arr' delimited by `delimiter'. */ public static String join(Iterable<? extends Object> arr, String delimeter) { StringBuilder str = new StringBuilder(); boolean first = true; for (Object ob : arr) { if (first) { first = false; } else { str.append(delimeter); } str.append(ob); } return str.toString(); } /** * Concatenate a list of values together as a string using the specified * delimiter. * * @param arr The array to convert to a string. * @param delimeter A string that will separate each element in `arr'. * @return All elements of `arr' delimited by `delimiter'. */ public static String join(Object[] arr, String delimeter) { return join(Arrays.asList(arr), delimeter); } /** * Concatenate a list of values together as a string. * * @param arr The array to convert to a string. * @return All elements of `arr' delimited by a comma and space (", "). */ public static String join(Iterable<? extends Object> arr) { return join(arr, ", "); } /** * Concatenate a list of values together as a string using the comma * delimiter. * * @param arr The array to convert to a string. * @return All elements of `arr' delimited by a comma and space (", "). */ public static String join(Object[] arr) { return join(Arrays.asList(arr), ", "); } }