Here you can find the source of join(Object[] array, char separator)
Parameter | Description |
---|---|
array | array to join |
separator | char to separate values |
public static String join(Object[] array, char separator)
//package com.java2s; /*/*from ww w. ja v a 2 s . c o m*/ * Copyright 2013 Agorava * * 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.Arrays; import java.util.Collection; public class Main { /** * Join a collection of Object with a given character as a separator * * @param collection collection to join * @param separator char to separate values * @return resulting string of the concatained values with separator */ public static String join(Collection collection, Character separator) { String res = ""; if (collection != null && separator != null) { for (Object s : collection) { res += s.toString() + separator; } res = res.substring(0, res.length() - 1); } return res; } /** * Join an array of Object with a given character as a separator * * @param array array to join * @param separator char to separate values * @return resulting string of the concatained values with separator */ public static String join(Object[] array, char separator) { if (array != null) return join(Arrays.asList(array), ','); else return ""; } }