public static Object min(Collection col) public static Object min(Collection col, Comparator comp) public static Object max(Collection col) public static Object max(Collection col, Comparator comp)
import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; public class MainClass { public static void main(String args[]) { String str[] = { "B", "H", "L", "M", "R" }; List list = Arrays.asList(str); System.out.println(Collections.min(list)); System.out.println(Collections.max(list)); Comparator comp = Collections.reverseOrder(); System.out.println(Collections.min(list, comp)); System.out.println(Collections.max(list, comp)); } }
B R R B