I have one string which contain delimiter suppose "?". Now I want to print a string which is separated by "?"
Suppose the String is
String str = "My?Name?Is?Pramod?Deore";
Now I want output as 5 string which are 1)My 2)Name 3)Is 4)Pramod 5)Deore
I had tried following program but it gives exception
Exception is as
Life is easy because we write the source code.....
It throws as exception because ? has special meaning in regular expressions.
? means Zero or one occurrence
change this line from arr = str.split("?"); to arr = str.split("\\?"); It
Reason: String p = "?"; // regex sees this as the "?" metacharacter
String p = "\?"; // the compiler sees this as an illegal Java escape sequence
String p = "\\?"; // the compiler is happy, and regex sees a question mark, not a metacharacter