Software >> Development >> Languages >> Java >> Examples >>  How to replace a string

String Before = "AppleOrange"; String After = Before.replace("Orange","Pear"); Result :- Before = "AppleOrange" After = "ApplePear"