String name = "xxx.jpg"; String type = name.substring(name.lastIndexOf('.')); System.out.println(type);