In Java:
String base = "a|a||";
String[] stri= .split("\\|");
produces a string array with length 2.
On the other hand in python:
base = "a|a||"
base.split("|")
produces an array with length 4. What do I have to do to get the same result in Java?
Use split with limit set to negative value:
String base = "a|a||";
String[] stri= .split("\\|", -1);
From the docs (the number at the and is n):
If n is non-positive then the pattern will be applied as many times as possible and the array can have any length.
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