String x = \"axe pickaxe\"; x = x.replace(\"axe\", \"sword\"); System.out.print(x);
By this code, I am trying to replace the exact word axe>
axe>
If you only want to replace the first occurrence, there is a method replaceFirst in String object.
replaceFirst
String
String x = "axe pickaxe"; x = x.replaceFirst("axe", "sword"); System.out.print(x); //returns sword pickaxe