Java Collection Element Get getHighest(final Collection elements, final Comparator c)

Here you can find the source of getHighest(final Collection elements, final Comparator c)

Description

Retrieve highest element contained in a collection.

License

Open Source License

Parameter

Parameter Description
T type of elements
elements collection of elements from which highest is returned
c Comparator to find highest

Return

highest element

Declaration

public static <T> T getHighest(final Collection<? extends T> elements, final Comparator<T> c) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010-2016 Alexander Kerner. All rights reserved.
 *
 * 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./*from   www  .ja  va  2  s . co m*/
 ******************************************************************************/

import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;

public class Main {
    public static <T extends Comparable<T>> T getHighest(final Collection<? extends T> elements) {

        return Collections.max(elements);
    }

    /**
     * Retrieve highest element contained in a collection.
     *
     * @param <T>
     *            type of elements
     * @param elements
     *            collection of elements from which highest is returned
     * @param c
     *            {@link Comparator} to find highest
     * @return highest element
     */
    public static <T> T getHighest(final Collection<? extends T> elements, final Comparator<T> c) {

        return Collections.max(elements, c);
    }
}

Related

  1. getElementFromSize1(Collection collection)
  2. getEntropy(Collection values)
  3. getEnumNames( Collection values)
  4. getFlatString(Collection elements)
  5. getGivenClassObject(Collection coll, Class clazz)
  6. getImplement(Class aClass, Collection> classCollection)
  7. getIndex(Object collectionOrArray, int index)
  8. getIndexedValue(Object collection, int index)