I have this code:
String string = "_a_b___";
String[] parts = string.split("_");
The result is that variable parts has only three elements
parts[0] = ""
parts[1] = "a"
parts[2] = "b"
This is weird, because there are five "_" chars, so after splitting there should be six elements, not only three of them.
I want
parts[0] = ""
parts[1] = "a"
parts[2] = "b"
parts[3] = ""
parts[4] = ""
parts[5] = ""
How to do that? Thank you very much!
From Java documentation:-
Trailing empty strings are therefore not included in the resulting array.
Trysplit("_",6)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With