Here you can find the source of getHighest(final Collection extends T> elements, final Comparator
Parameter | Description |
---|---|
T | type of elements |
elements | collection of elements from which highest is returned |
c | Comparator to find highest |
public static <T> T getHighest(final Collection<? extends T> elements, final Comparator<T> c)
//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); } }