Does "\ n" count as a character in a string?
Yes, in java it is \nconsidered as one character
h e y \n y o \n s u p \n yello
-------------------------------
0 1 2 3 4 5 6 7 8 9 10 11
That's why you got 11fortest.indexOf("yello")
You can try this as evidence:
String str = "\n";
System.out.println(str.length());
will give you 1as a day off
source
share