with this String:
String test = "hey\nyo\nsup\nyello";
and I call
System.out.println(test.indexOf("yello")); 
I get 11, how is that number produced? and does "\n" count as a character in the String?
does "\n" count as a character in the String?
Yes, in java \n is treated as a single 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
Thats why you got 11 for test.indexOf("yello")
You can try this as a proof:
String str = "\n";
System.out.println(str.length());
will give you 1 as the output
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With