General J2EE: problem with split function when the delimiter is "\"

  1. I have to split a string based on "\" symbol. But, it is throwing exception. String str = "ram\raj"; String strs[] = str.split("
    "); for (int i=0; i<strs.length; i++ ) { System.out.println(str); } I have tried in the second model also. But, failed. System.out.println(str.substring(str.indexOf("
  2. String strs[] = str.split("\\\\"); You need to realize that the "" is a regular expression.. so back slash needs to be escaped for the reg exp too. Regards, Rakesh.
  3. Your original string is not properly escaped. First of all the program should not get compiled. your string should be "ram