I have a String = \"Hello-new-World\". And when i use the split() method with different regex values, it acts differently.
String str = \"Hello-new-world\"
Strin
split method takes regular expression as input. The pipe is a special character for regular expression, so if you want to use it tou need to escape the special character. Ther are multiple solutions:
You need to escape the "pipe" character
str.split("\\|");
Or you can use the helper quote:
str.split(Regexp.quote("|"))
Or between sqares:
str.split("[|]");