java string split – escape |

You read the java doc. Yep, super easy.

String s=”a,b,c”

String () aStr=s.split(“,”);

aStr will hold

A b c

How about if s is “a|b”?

Before pulling your hairs off, here is the answer:

S.split(“\\|”);

Do think about it why, though.

Answer: Because | and \ are special characters in java so you have to escape them.