我在分割 String
时遇到了问题。
我想分裂一个 String
与一些分隔符,但不失去该分隔符。
当我们在 Java 中使用 somestring.split(String separator)
方法时,它拆分了 String
,但是从 String
中删除了分隔符部分。我不想这样。
我想要的结果如下:
String string1="Ram-sita-laxman";
String seperator="-";
string1.split(seperator);
产出:
[Ram, sita, laxman]
但我希望得到的结果与下面的一样:
[Ram, -sita, -laxman]
有办法得到这样的输出吗?