Page 1 of 1

length()

Posted: Wed May 10, 2023 3:18 pm
by hin1129
String str = "hello\r\n" + "world";
System.out.println(str.length());

why is answer 12?
hello and world should be 10 in total.
so which of the characters (\r\n) are not counted?

Re: length()

Posted: Thu May 11, 2023 12:19 am
by admin
Both are counted. That is why "hello\r\n" is 7 and "world" is 5. Total 7+5 is 12.