A

Admin • 828.70K Points
Coach

Q. String str1 = "Kolkata".replace('k', 'a');

In the above statement, the effect on string Kolkata is

  • (A) The first occurrence of k is replaced by a.
  • (B) All characters k are replaced by a.
  • (C) All characters a are replaced by k.
  • (D) Displays error message
  • Correct Answer - Option(B)
  • Views: 15
  • Filed under category Java
  • Hashtags:

Explanation by: Admin
replace() method returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.