title: How to check the extension of a Java 7 Path
body: <p>I'd like to check if a <a href="http://docs.oracle.com/javase/7/docs/api/java/nio/file/Path.html">Path</a> (introduced in Java 7) ends with a  certain extension. I tried the <code>endsWith()</code> method like so:</p>
  
  <pre><code>Path path = Paths.get("foo/bar.java")
  if (path.endsWith(".java")){
      //Do stuff
  }
  </code></pre>
  
  <p>However, this doesn't seem to work because <code>path.endsWith(".java")</code> returns false. It seems the <code>endsWith()</code> method only returns true if there is a complete match for everything after the final directory separator (e.g. <code>bar.java</code>), which isn't practical for me.</p>
  
  <p>So how can I check the file extension of a Path?</p>