Here you can find the source of join(Collection> col, String delim)
public static String join(Collection<?> col, String delim)
//package com.java2s; /**//from www . j a v a 2 s . c o m * Tencent is pleased to support the open source community by making MSEC available. * * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved. * * Licensed under the GNU General Public 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 * * https://opensource.org/licenses/GPL-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 { public static String join(Collection<?> col, String delim) { StringBuilder sb = new StringBuilder(); Iterator<?> iter = col.iterator(); if (iter.hasNext()) sb.append(iter.next().toString()); while (iter.hasNext()) { sb.append(delim); sb.append(iter.next().toString()); } return sb.toString(); } public static String join(Map<?, ?> map, String delim) { StringBuilder sb = new StringBuilder(); Iterator<?> iter = map.entrySet().iterator(); if (iter.hasNext()) { Map.Entry<?, ?> entry = (Map.Entry<?, ?>) iter.next(); sb.append(entry.getKey() + ":" + entry.getValue()); } while (iter.hasNext()) { sb.append(delim); Map.Entry<?, ?> entry = (Map.Entry<?, ?>) iter.next(); sb.append(entry.getKey() + ":" + entry.getValue()); } return sb.toString(); } }