Using String.split() , you will get an empty string as an element of the array when you have back to back in your string on which you are splitting.
For example, if you divide xyyz by y , the second element will be an empty string. To avoid this, you can simply add a quantifier to the delimiter - y+ , so that the decay occurs at 1 or more iterations.
In your case, this is due to the fact that you used \\D0* , which will correspond to each asymmetric character and is divided into it. So you have back to back. You can, of course, use the surrounding quantifier here:
Pattern reg = Pattern.compile("(\\D0*)+");
But you really need: \\D+0* there.
However, if you only need the number sequence from your string, I would use the Matcher#find() method, and \\d+ as a regular expression.
source share