when i was using Collections class to find the minimum of the integer element in list(Collections.min(array)), it was throwing error. but finding the minmum element manually by iterating over each element of list test got verified. Why so?
package com.codegym.task.task08.task0822;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Collections;
/*
Minimum of N numbers
*/
public class Solution {
public static void main(String[] args) throws Exception {
List<Integer> integerList = getIntegerList();
System.out.println(getMinimum(integerList));
}
public static int getMinimum(List<Integer> array) {
// Find the minimum here
int x = Collections.min(array);
return x;
}
public static List<Integer> getIntegerList() throws IOException {
// Create and initialize a list here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(reader.readLine());
ArrayList<Integer> list = new ArrayList<>(N);
for(int i=0; i<list.size(); i++)
{
list.add(i, Integer.parseInt(reader.readLine()));
}
return list;
}
}