length()

Oracle Certified Foundations Associate Java Certification Questions and Discussion
1Z0-811

Moderator: admin

Post Reply
hin1129
Posts: 9
Joined: Fri Apr 14, 2023 2:20 pm
Contact:

length()

Post 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?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: length()

Post by admin »

Both are counted. That is why "hello\r\n" is 7 and "world" is 5. Total 7+5 is 12.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests