How to get list of Integer from String
ArrayList<Integer> lst = new ArrayList<Integer>();
for (String field : number.split(" +"))
lst.add(Integer.parseInt(field));
With Java 8+:
List<Integer> lst =
Arrays.stream(number.split(" +")).map(Integer::parseInt).collect(Collectors.toList());
You can use a Scanner
to read the string one integer at a time.
Scanner scanner = new Scanner(number);
List<Integer> list = new ArrayList<Integer>();
while (scanner.hasNextInt()) {
list.add(scanner.nextInt());
}