how could I get values entered in a single line by the user eq: 1, 3, 400, 444, etc.. into an array. I know I must declare a separator in this case the comma ",". Could someone help
Thanks
how could I get values entered in a single line by the user eq: 1, 3, 400, 444, etc.. into an array. I know I must declare a separator in this case the comma ",". Could someone help
Thanks
You can use much simpler separator in
String.split()
like","
but the more complex"\\s*,\\s*"
additionally strips whitespaces around comma.It's the right answer, "\\s*,\\s*" is a regular expression, regex is very useful for the string parsing.
Try this:
Now
answer
is an array with the numbers in the string as integers. The other answers just split the string, if you need actual numbers you need to convert them.You want to use split: