如何使用 Java split 获得与 Python split 相同的结果

How do I get the same results with Java split as with Python split

在Java中:

String base = "a|a||";
String[] stri= .split("\|");

生成长度为 2 的字符串数组。

另一方面 python:

base = "a|a||"
base.split("|")

生成一个长度为 4 的数组。 我需要做什么才能在 Java 中获得相同的结果?

使用限制设置为负值的拆分:

String base = "a|a||";
String[] stri= .split("\|", -1);

来自docs(和处的数字是n):

If n is non-positive then the pattern will be applied as many times as possible and the array can have any length.