Here you can find the source of join(Object[] array, String separator)
Parameter | Description |
---|---|
array | of strings |
separator | a parameter |
public static String join(Object[] array, String separator)
//package com.java2s; /*/*w w w . ja va2 s . co m*/ * StringUtil.java Copyright 2004-2007 KUBO Hiroya (hiroya@cuc.ac.jp). 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.List; public class Main { /** * join list of strings by separator * * @param stringList * list of strings * @param separator * null is accepted (treated same as ""). * @return joined string */ public static String join(List<String> stringList, String separator) { StringBuilder ret = new StringBuilder(); for (int i = 0; i < stringList.size(); i++) { if (i != 0) { if (separator != null) { ret.append(separator); } } ret.append(stringList.get(i)); } return ret.toString(); } /** * join array of strings by separator * * @param array * of strings * @param separator * @return joined string */ public static String join(Object[] array, String separator) { StringBuilder ret = new StringBuilder(); for (int i = 0; i < array.length; i++) { if (i != 0) { if (separator != null) { ret.append(separator); } } ret.append(array[i]); } return ret.toString(); } }