ArrayList<Integer> LIST = new ArrayList<Integer>(); while (sc.hasNextInt()) { int i = sc.nextInt(); LIST.add(i); }