Java Collection First getFirstSortedItem( Collection items, T defaultValue)

Here you can find the source of getFirstSortedItem( Collection items, T defaultValue)

Description

get First Sorted Item

License

Open Source License

Declaration

public static <T extends Comparable<? super T>> T getFirstSortedItem(
            Collection<T> items, T defaultValue) 

Method Source Code

//package com.java2s;
/* ***** BEGIN LICENSE BLOCK *****
 *
 * This file is part of Weave.//from ww w  .j a  va  2s. com
 *
 * The Initial Developer of Weave is the Institute for Visualization
 * and Perception Research at the University of Massachusetts Lowell.
 * Portions created by the Initial Developer are Copyright (C) 2008-2015
 * the Initial Developer. All Rights Reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/.
 * 
 * ***** END LICENSE BLOCK ***** */

import java.util.ArrayList;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class Main {
    public static <T extends Comparable<? super T>> T getFirstSortedItem(
            Collection<T> items, T defaultValue) {
        List<T> sortedItems = new ArrayList<T>(items);
        Collections.sort(sortedItems);
        for (T item : sortedItems)
            return item;
        return defaultValue;
    }
}

Related

  1. getFirstItemInCollection(Collection collection)
  2. getFirstN(Collection objects, int n)
  3. getFirstNonNull(Collection c)
  4. getFirstNotNullValue(final Collection collection)
  5. getFirstOrNull(final Collection collection)
  6. getUnionSize(Collection firstCollection, Collection secondCollection)
  7. intersect(Collection firstSet, Collection secondSet)
  8. nullSafeFirstElement(Collection collection)
  9. removeFirst(Collection collection, int numToRemove)