I have three part string with each part seperated by $ symbol
For example,
String s = "abc$efg$xyz";
Now when I split it using split method like this:
String values[] = s.split("$");
It values array contains that entire string as a single element.
But when I use this:
String values[]=s.split("\\$");
It perfectly works what I wanted meaning
now the values array contains abc,efg and xyz on index 0,1 and 2 respectively.
I was wondering why that first split didn’t work as I used similar split when splitting on a single white space using split(" ");
Because the character
$is a reserved token used in regular expressions to mark the end of a line. That’s why you have to escape it using\\.