Here you can find the source of join(String[] array)
Parameter | Description |
---|---|
array | String array. |
public static String join(String[] array)
//package com.java2s; /*//from ww w . ja v a2s . c o m * Copyright 1999-2011 Alibaba Group. * * 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.*; public class Main { /** * join string. * * @param array String array. * @return String. */ public static String join(String[] array) { if (array.length == 0) return ""; StringBuilder sb = new StringBuilder(); for (String s : array) sb.append(s); return sb.toString(); } /** * join string like javascript. * * @param array String array. * @param split split * @return String. */ public static String join(String[] array, char split) { if (array.length == 0) return ""; StringBuilder sb = new StringBuilder(); for (int i = 0; i < array.length; i++) { if (i > 0) sb.append(split); sb.append(array[i]); } return sb.toString(); } /** * join string like javascript. * * @param array String array. * @param split split * @return String. */ public static String join(String[] array, String split) { if (array.length == 0) return ""; StringBuilder sb = new StringBuilder(); for (int i = 0; i < array.length; i++) { if (i > 0) sb.append(split); sb.append(array[i]); } return sb.toString(); } public static String join(Collection<String> coll, String split) { if (coll.isEmpty()) return ""; StringBuilder sb = new StringBuilder(); boolean isFirst = true; for (String s : coll) { if (isFirst) isFirst = false; else sb.append(split); sb.append(s); } return sb.toString(); } /** * is empty string. * * @param str source string. * @return is empty. */ public static boolean isEmpty(String str) { if (str == null || str.length() == 0) return true; return false; } }