0

I am trying to split a string as follows, "Client|Role". My regex is "|".

I expected two substrings as "Client" and "Role", but what I get is each and every character as a substring including the character in my regex. Why I am getting like this? Please help, Thanks in advance.

My code is as follows,

String output = "Client|Role";
String values[] = output.split("|");
Heyyou
  • 151
  • 1
  • 13
  • Can you please mention the duplicate question link. @Wiktor Stribizew – Heyyou Jun 27 '19 at 08:18
  • Kishore, just reload this page and it should appear ontop of your question (in a yellow box). – Tom Jun 27 '19 at 08:19
  • @Kishore [This](https://stackoverflow.com/a/10796174/3832970) and [this](https://stackoverflow.com/a/21524670/3832970) answers summing up to 837 upvotes. – Wiktor Stribiżew Jun 27 '19 at 09:38

1 Answers1

-1

You can split like this..

String b = "Client|Role";       
String[] elements = b.split("\\|");
Rowi
  • 545
  • 3
  • 9