public static void main(String[] args) {
File file = new File("images/cougar.jpg");
String ext = getExtension(file);
String JPG = "jpg";
if(JPG.equals(ext))
System.out.println("equal");
else
System.out.println("not equal");
}
private static String getExtension(File file) {
String s = file.getPath();
int dot = s.lastIndexOf(".");
if(dot > -1 && dot < s.length())
return s.substring(dot+1);
return null;
}