The regex \s+
matches one or more whitespaces, so it will split
into 4 values:
"12:40:11", "8", "5", "87"
As a Java string literal, this pattern is "\\s+"
.
If you want to get all 6 numbers, then you also want to split on :
, so the pattern is \s+|:
. As a Java string literal this is "\\s+|:"
.
References
On Scanner
Instead of using String.split
, you can also use java.util.Scanner
, and useDelimiter
the same as what you'd use to split
. The advantage is that it has int nextInt()
that you can use to extract the numbers as int
(if that's indeed what you're interested in).
Related questions
"\\w.([:])."
would work, I can elaborate on where the logic went wrong. Right now I'm not even sure how you came to that. – Bewail[12,40,11,8,5,87]
? – Detonator