Advertisements
Advertisements
Question
Describe the purpose of the following function with its syntax:
replace()
Code Writing
Solution
This function can be used to swap out every use of a character for another character or to swap out every occurrence of a String for another String.
Example:
String s = "By the people for the people";
s = s.replace("people", "teachers"); System.out.println(s);
Output: By the teachers for the teachers
shaalaa.com
Is there an error in this question or solution?
Chapter 4: String Handling - EXERCISES [Page 289]