-2

Java string split: If I split "0" with delimiter "|" I expect array of one element as in ["0"]. But what I actually get is {"","0"}

How to fix this? Thanks

pete
  • 1,878
  • 2
  • 23
  • 43
  • 4
    You need to escape `|` –  Feb 05 '15 at 21:42
  • Hi, I do not agree this is a duplicate, because people might not realize it's pipe symbol that's causing it until they see this question. – pete Feb 05 '15 at 21:45

1 Answers1

0

Argument to string split is a regex not a string. So pipeline symbol does not mean pipeline symbol. Why does String.split need pipe delimiter to be escaped?

Using "\\|" worked

Community
  • 1
  • 1
pete
  • 1,878
  • 2
  • 23
  • 43