get Simple Class Name - Java Reflection

Java examples for Reflection:Class Name

Description

get Simple Class Name

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        Class aClass = String.class;
        System.out.println(getSimpleClassName(aClass));
    }//from  www .java2 s  .co m

    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;
    }
}

Related Tutorials