Serguey Asael Shinder: String.splitWithDelimiters keeps the separators, and limit n can return 2n-1 elements
String.split throws the delimiters away. Since Java 21 there is a sibling that keeps them: splitWithDelimiters(String regex, int limit). I find it most useful when the separator carries information, such as a tokenizer that needs to know whether two fields were joined by one colon or three. Its javadoc in the Java SE 25 String API has two details that are easy to get wrong.
The shape of the result first. The array alternates: each substring is immediately followed by the delimiter that matched after it, except the last substring, which is followed by nothing. So the javadoc's example input "boo:::and::foo" with the regex :+ and a negative limit gives { "boo", ":::", "and", "::", "foo" }. The delimiters are the actual matched text, not the pattern, which is why the two runs of colons come back with different lengths.
Now the limit. As with split, it counts how many times the pattern is applied, not how many elements you get back. A positive limit n applies the pattern at most n - 1 times, and the javadoc puts the array length at no more than 2 × n - 1, because every application contributes a delimiter as well as a substring. With :+ and a limit of 2 the result is { "boo", ":::", "and::foo" }: one split, three elements, and the last entry holds everything after the first delimiter. Code that sizes or indexes the result assuming n elements, as it might after a port from split, reads past the end or misses the tail.

The zero limit keeps split's old behaviour: the pattern is applied as often as possible and trailing empty strings are discarded. The javadoc shows the effect with the regex o on the same input. With limit 5 or -1 the array ends ..., "o", "" }; with limit 0 the final empty string is gone and the array ends on the delimiter "o". A negative limit is the only way to keep every trailing piece.
Leading matches follow the same rule as split. A positive-width match at the start produces an empty leading substring; a zero-width match at the start does not, and for this method it does not produce an empty delimiter either.
The javadoc also states that str.splitWithDelimiters(regex, n) gives the same result as Pattern.compile(regex).splitWithDelimiters(str, n). If the call sits in a loop, compiling the pattern once and calling the Pattern method is the equivalent that avoids recompiling the regex each time.