title: How to match an exact match in a string using Java
body: <p>I am trying to check if a string contains an exact match. 
  For example:<br>
  String str = "This is my string that has -policy and -p" </p>
  
  <p>How can I do the following:</p>
  
  <pre><code>if (str.contains("-p")) {  // Exact match to -p not -policy
  System.out.println("This is -p not -policy");
  
  }
  </code></pre>