просит пользователя ввести список строк со сканера; затем преобразуем его в список целых чисел.
Код: Выделить всё
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
public class BinarySearch {
public static void main(String[] args)throws NumberFormatException{
Scanner s = new Scanner(System.in);
//convert List of String to Stream of String
//convert Stream of String to Stream of Integer
//collect Stream of Integer into List of Integer
List arr =
splitWords(s.nextLine())
.stream()
.map(Integer::parseInt)
.collect(Collectors.toList());
// System.out.println(Arrays.toString(arr.toArray()));
}
public static List splitWords(String s) {
System.out.println(s);
return s.isEmpty() ? List.of() : Arrays.asList(s.split(" "));
}
}
Подробнее здесь: https://stackoverflow.com/questions/784 ... texception