In this article, we will see how to use format method of String to replace all word occurrences in Java.
Lets look to our code.
String s1;
s1.replaceAll("andromeda","vega");
Lets see it in an example.
In above example, we replaced all "andromeda" words in string object with "vega" and print it to terminal.