Here you can find the source of toSortedStrings(final Collection extends Object> objects)
Parameter | Description |
---|---|
objects | the given collection of objects |
public static List<String> toSortedStrings(final Collection<? extends Object> objects)
//package com.java2s; /*//from www . java 2 s. c o m * StringUtils.java * * Created on October 4, 2006, 2:36 PM * * Description: * * Copyright (C) 2006 Stephen L. Reed. * * This program 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 2 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, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; public class Main { /** Returns a sorted list of the strings corresponding to the given collection of objects. * * @param objects the given collection of objects * @return a sorted list of the strings */ public static List<String> toSortedStrings(final Collection<? extends Object> objects) { //Preconditions assert objects != null : "objects must not be null"; final List<String> strings = new ArrayList<>(); for (final Object obj : objects) { strings.add(obj.toString()); } Collections.sort(strings); return strings; } }