0

From what I have read having a \ will ignore the break character in a Java string. So I have the following code:

//requestedFile is created from a substring from above and contains the string "WebRoot\"

if(requestedFile == "WebRoot\\" {
do stuff
}

Are these not the same thing?

  • @Marvin Right, I was comparing the objects with == instead of using .equals. Duh, Thank you –  Apr 18 '17 at 21:36
  • The backslash is an escape character so \\ is actually converted down to a single \ for usage purposes. Also, you will generally want to use the .equals() method to compare objects so you are comparing what you actually want to compare. vs comparing to see if two objects are the exact same object. – Jason K. Apr 18 '17 at 21:37

0 Answers0