1private static int findMin(int[] array) {
2 int min = array[0];
3 for(int i=1;i<array.length;i++) {
4 if(min > array[i]) {
5 min = array[i];
6 }
7 }
8 return min;
9 }
1Integer[] num = { 2, 4, 7, 5, 9 };
2 // using Collections.min() to find minimum element
3 // using only 1 line.
4 int min1 = Collections.min(Arrays.asList(num));
5
6 // using Collections.max() to find maximum element
7 // using only 1 line.
8 int max1 = Collections.max(Arrays.asList(num));
9 System.out.println(min1); // 2
10 System.out.println(max1); // 9