[Solved] Why there are empty string while trying to split a string in Java? And how to fix it?


It’s because you’re splitting by a single character, you would have to do this eagerly:

String[] Operators = stringNumbers.split("[0-9.]*");

Or you can filter the results:

String[] Operators = Arrays.stream(stringNumbers.split("[0-9.]"))
    .filter(str -> !str.equals(""))
    .toArray(String[]::new);

5

solved Why there are empty string while trying to split a string in Java? And how to fix it?