I have this
String str = "a,pnp,a|pnp,lab2|pnp,a|pnp,lab2,utr,utr";
String[] strings = str.split("|");
This code won’t split around the ‘|’ character, instead it splits every character like
strings[0] == "a";
strings[1] == ",";
and so on.
How to get this working to get
strings[0] == "a,pnp,a"
strings[1] == "pnp,lab2"
...
split()takes a regular expression, and|is reserved for regex OR, so you need to escape it:or even better: