What will be displayed on the screen after the following code is executed?
String str = "Plan to sing today.";
String newStr = str.replace("to", "2");
System.out.println(newStr.length());

Respuesta :

tanoli

Answer:

17

Explanation:

str string contains 19 character in total.

When we called str.replace("to","2");, it basically replaced all sub string to with 2 so as we have to occurred on 2 places in given string so it replaces 4 characters with 2 characters.

So after getting the length of new string, it returns 17.

Answer:

The number 17

Explanation:

The character str string contains 19 characters.

When the command str. replace("to", "2"); it basically is replaces all sub string to with 2 so that we have "to"occuring on 2 places in a given string. Therefore, it replaces 4 characters with only two characters.

So, after getting the length of the new string, it returns to the number 17.