I am having problem to split string in java. it gives java.util.regex.Pattern.error.
String name = One\Two\Three.
String[] str = name.split("\\");
for(int i =0; i < str.length ; i++)
System.out.println(str[i]);
I put another \ as escape character but not working.
help me.
One\Two\Threeis not a valid string literal (you need quotes and you need to escape the backslashes).works fine.
Explanation
String#splitexpects a regular expression. The backslash character has a special meaning inside regular expressions, so you need to escape it by using another backslash:\\Now because the backslash character also has a special meaning inside Java string literals, you have to double each of these again, resulting in"\\\\".