Returns the name of a class without the package name : Class Method Field Name « Reflection « Java






Returns the name of a class without the package name

 

public class Utils {
  /**
   * Returns the name of a class without the package name.  For example: if
   * input = "java.lang.Object" , then output = "Object".
   * @param fully qualified classname
   * @return the unqualified classname 
   */
  public static String getShortClassName(final String className) {
      if (className != null) {
          final int index = className.lastIndexOf('.');

          return className.substring(index + 1);
      }
      return null;
  }
}

   
  








Related examples in the same category

1.Create a new instance given a class name
2.Load a class given its name.
3.Get the short name of the specified class by striping off the package name.
4.Returns an instance of the given class name, by calling the default constructor.
5.Get non Package Qualified Name
6.Returns the package portion of the specified class
7.Format a string buffer containing the Class, Interfaces, CodeSource, and ClassLoader information for the given object clazz.
8.Create a unique hash for Constructor and method