Here you can find the source of joinSorted(Collection extends Comparable> s, String delimiter)
@SuppressWarnings({ "unchecked", "rawtypes" }) public static String joinSorted(Collection<? extends Comparable> s, String delimiter)
//package com.java2s; /*/*from w ww .jav a 2s .c o m*/ * Copyright (c) Erasmus MC * * This file is part of TheMatrix. * * TheMatrix is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.List; public class Main { @SuppressWarnings({ "unchecked", "rawtypes" }) public static String joinSorted(Collection<? extends Comparable> s, String delimiter) { List list = new ArrayList(s); Collections.sort(list); return join(list, delimiter); } public static String join(Collection<?> s, String delimiter) { StringBuffer buffer = new StringBuffer(); Iterator<?> iter = s.iterator(); if (iter.hasNext()) { buffer.append(iter.next().toString()); } while (iter.hasNext()) { buffer.append(delimiter); buffer.append(iter.next().toString()); } return buffer.toString(); } public static String join(Object[] objects, String delimiter) { StringBuffer buffer = new StringBuffer(); if (objects.length != 0) buffer.append(objects[0].toString()); for (int i = 1; i < objects.length; i++) { buffer.append(delimiter); buffer.append(objects[i].toString()); } return buffer.toString(); } }