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
πŸ’¬ Discuss
βœ… Correct Answer: (B) All characters k are replaced by a.
Explanation: replace() method returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.
Explanation by: Shiva Ram
replace() method returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
128
Total Visits
πŸ“½οΈ
1 y ago
Published
πŸŽ–οΈ
Shiva Ram
Publisher
πŸ“ˆ
93%
Success Rate