title: Java - String replace exact word
body: <pre><code>String x = "axe pickaxe";
  x = x.replace("axe", "sword");
  System.out.print(x);
  </code></pre>
  
  <p>By this code, I am trying to replace the exact word <code>axe</code> with <code>sword</code>. However, if I run this, it prints <code>sword picksword</code> while I would like to print <code>sword pickaxe</code> only, as <code>pickaxe</code> is a different word from <code>axe</code> although it contains it. How can I fix this? Thanks</p>