Java - Write code to get Extension from File path String

Requirements

Write code to get Extension from File path String

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String path = "c://a//asdf/asdf/as/df/asd/f/asd/f/book2s.com";
        System.out.println(getExtension(path));
    }/*from ww w . j  ava  2 s  .c  om*/

    public static String getExtension(String path) {
        String[] split = path.split("\\.");
        if (split.length > 1) {
            String ext = split[split.length - 1];
            if (ext.length() <= 4) {
                return ext;
            }
        }
        return "";
    }
}