k238 k238 -4 years ago 178
Java Question

Java split() with regex

I have been trying to split up a String, which contain a number of words separated by a random amount of spaces

String numbers = " 3534 65 884 76 45 34";

String[] listOfnumbers = numbers.split("\\s+");

but I keep getting an empty string saved in the first position of the array.

Am I doing something wrong?

Answer Source

Have you tried to trim the string first?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download