import java.io.*; import java.util.ArrayList; import java.util.Collections; import java.util.List; /* Задача по алгоритмам Написать программу, которая: 1. вводит с консоли число N > 0 2. потом вводит N чисел с консоли 3. выводит на экран максимальное из введенных N чисел. */ public class Solution { public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String raz = reader.readLine(); int razi = Integer.parseInt(raz); List myList = new ArrayList(); for(int i=0; i<razi;i++){ String x = reader.readLine(); int y = Integer.parseInt(x); myList.add(y); } int maxi = Collections.max(myList); System.out.println(Collections.max(myList)); } } If you remove the line int maxi = Collections.max(myList); then the code runs without problems. But I was interested, why I can not assign the maximum value from the list variable maxi ? IDE shows an error.