标签:
package chapter1; import java.util.Comparator; public class FindMax2 { public static void main (String [] args ){ String [] arr ={"z","q","a"}; System.out.println(FindMax(arr, new CaseInsentiveCompare())); } public static <T> T FindMax (T[] arr, Comparator<? super T> cmp){ int maxIndex =0; for (int i =0; i<arr.length;i++){ if (cmp.compare(arr[i], arr[maxIndex])>0){ maxIndex = i; } } return arr[maxIndex] ; } } class CaseInsentiveCompare implements Comparator<String>{ public int compare(String lhs, String rhs) { // TODO Auto-generated method stub return lhs.compareToIgnoreCase(rhs); } }
标签:
原文地址:http://www.cnblogs.com/chuiyuan/p/4449011.html