得到一个简单的类名

public class Main {
    public static void main(String[] argv) {
        Class aClass = String.class;
        System.out.println(getSimpleClassName(aClass));
    }

    public static String getSimpleClassName(Class aClass) {
        return getSimpleClassName(aClass.getName());
    }

    public static String getSimpleClassName(String qualifiedClassName) {
        return getLastToken(qualifiedClassName, '.');
    }

    public static String getLastToken(String str, char separator) {
        int pos = str.lastIndexOf(separator);
        if (pos != -1) {
            str = str.substring(pos + 1);
        }
        return str;
    }
}

你可能感兴趣的:(得到一个简单的类名)