Hej, rozwiązuję zadanie z hackerrank i mam do sczytania wiele linijek zawierających różną liczbę liczb. Rozkminiłem sobie, że z każdej linijki będę tworzyć listę Integerów a następnie wrzucał to do listy list. Wszystko ładnie działa, ale mam problem z zamknięciem scannera. Po utworzeniu listy list wciąż nasłuchuje.
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
List<List<Integer>> listList = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
while (scanner.hasNextLine()) {
List<Integer> integerList = new ArrayList<>();
Scanner lineScanner = new Scanner(scanner.nextLine());
while (lineScanner.hasNextInt()) {
integerList.add(lineScanner.nextInt());
}
listList.add(integerList);
lineScanner.close();
}
scanner.close();
System.out.println(listList);
}
}