public class Example
{
public static <AnyType> AnyType findMax(AnyType [] arr,Comparator<? super AnyType> cmp)
{
int maxIndex = 0;
for(int i = 1; i < arr.length; i++)
{
if(cmp.compare(arr[i], arr[maxIndex]) > 0)
{
maxIndex = i;
}
}
return arr[maxIndex];
}
/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
String str[] = {"zerjfka","alligator","crocodile",};
System.out.println(findMax(str,new CaseInsensitiveCompare()));
}
}
class CaseInsensitiveCompare implements Comparator<String>
{
@Override
public int compare(String str1, String str2)
{
// TODO Auto-generated method stub
return str1.compareToIgnoreCase(str2);
}
}