Skip to content

Instantly share code, notes, and snippets.

@lmatteis
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save lmatteis/2df1cb29d9aff356cf9f to your computer and use it in GitHub Desktop.

Select an option

Save lmatteis/2df1cb29d9aff356cf9f to your computer and use it in GitHub Desktop.
package school;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
public class MinMax<T> {
public T min;
public T max;
public MinMax(T min2, T max2) {
this.min = min2;
this.max = max2;
}
public static <E> MinMax<E> getMinMax(Collection<E> c) {
E min = Collections.min(c); // The method min(Collection<? extends T>) in the type Collections is not applicable for the arguments (Collection<E>)
E max = Collections.max(c);
MinMax<E> mm = new MinMax<E>(min, max);
return mm;
}
public static void main(String[] args) {
MinMax<String> mm = getMinMax(Arrays.asList("ciao", "aaa", "bb", "aabb", "zzz"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment