配列の最大値を求める
class Max { private Max() { } public static <T extends Comparable> T maximumOfArrayElements(T[] a){ T max = a[0]; for(T x : a){ if(max.compareTo(x) < 0){ max = x ; } } return max; } } class Sample { public static void main(String arg[]){ Integer[] data = { 1, -10, 3, 9, 7, 99, -25 }; Integer max = Max.maximumOfArrayElements(data); Double[] data_D = { 1.1, -10.5, 3.7, 9.98, 7.4, 9.9, -2.5 }; Double max_D = Max.maximumOfArrayElements(data_D); System.out.println("最大値:" + max); System.out.println("最大値:" + max_D); } }