Returns the package portion of the specified class : Class Method Field Name « Reflection « Java






Returns the package portion of the specified class

 

public class Utils {
  /**
   * Returns the package portion of the specified class
   * @param className the name of the class from which to extract the package
   * @return package portion of the specified class
   */
  public static String getPackageName(final String className) {
      if (className != null) {
          final int index = className.lastIndexOf('.');

          return ((index != -1) ? className.substring(0, index) : ""); // NOI18N
      }

      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 name of a class without the package name
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