Here you can find the source of join(String separator, CharSequence... elements)
public static String join(String separator, CharSequence... elements)
//package com.java2s; /*//from ww w .j a v a2 s . co m * Copyright 2000-2013 JetBrains s.r.o. * Copyright 2014-2014 AS3Boyan * Copyright 2014-2014 Elias Ku * Copyright 2017-2018 Eric Bishton * * 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.Iterator; public class Main { public static String join(String separator, CharSequence... elements) { // TODO: Replace this function with String.joinHaxeLib when we no longer support Java6/7. StringBuilder builder = new StringBuilder(); for (int i = 0; i < elements.length; i++) { builder.append(elements[i]); if (i < elements.length - 1) { builder.append(separator); } } return builder.toString(); } public static String join(String separator, Iterable<? extends CharSequence> elements) { // TODO: Replace this function with String.join when we no longer support Java6/7. StringBuilder builder = new StringBuilder(); Iterator<? extends CharSequence> iterator = elements.iterator(); while (iterator.hasNext()) { builder.append(iterator.next()); if (iterator.hasNext()) { builder.append(separator); } } return builder.toString(); } }