how to split string with some seperator but without removing that seperator in Java?

Posted by sag on Stack Overflow See other posts from Stack Overflow or by sag
Published on 2010-12-11T11:12:28Z Indexed on 2010/12/28 16:54 UTC
Read the original article Hit count: 200

Filed under:
|

Hi, I m facing problem in splitting string. Actually i want to split a string with some seperator but without loosing that seperator.

when we use somestring.split(String seperator) method in java it splits the string but removes the seperator part from string.It should not happen. I want result like below: Example::string1="Ram-sita-laxman";

     seperator="-";

     string1.split(seperator);

output : [Ram, sita, laxman]

but i want the result like :[Ram, -sita, -laxman]

is there a way to get output like this?

© Stack Overflow or respective owner

Related posts about java

Related posts about string