Answer the question
In order to leave comments, you need to log in
How to get all numbers from a string?
Good day.
Let's assume that we are given a certain string in which different numbers are listed to us separated by a space. How can we extract all these numbers from a string and write them into an int array?? The following are examples of lines
String numbers = "6 8 15 7 -8";
String numbers1 = "-88 36 15 1 45 90";
Answer the question
In order to leave comments, you need to log in
A more modern solution with streams and lambdas:
String numbers = "6 8 15 7 -8";
int result[] = Arrays.stream(numbers.split(" +")).mapToInt(Integer::parseInt).toArray();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question