A

Admin • 833.24K Points
Coach

Q. What is the output of the following code snippet?

Code:
String s1 = “Hello”;
System.out.println(sA)replaceAll(“l”, “z”));
  • (A) Hezzo
  • (B) Hezzz
  • (C) Hello
  • (D) None of the above
  • Correct Answer - Option(A)
  • Views: 22
  • Filed under category Java
  • Hashtags:

Explanation by: Admin

The replaceAll method in Java replaces all occurrences of a specified substring in a string with another substring. In this case, sA)replaceAll(“l”, “z”) returns “Hezzo”, which is the string “Hello” with all “l” characters replaced with “z”.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.