I\'d like to check if a Path (introduced in Java 7) ends with a certain extension. I tried the endsWith() method like so:
Path path = Paths.get
The Path class does not have a notion of "extension", probably because the file system itself does not have it. Which is why you need to check its String representation and see if it ends with the four five character string .java. Note that you need a different comparison than simple endsWith if you want to cover mixed case, such as ".JAVA" and ".Java":
path.toString().toLowerCase().endsWith(".java");