Java Utililty Methods Class Name Extract

List of utility methods to do Class Name Extract

Description

The list of methods to do Class Name Extract are organized into topic(s).

Method

StringextractClassName(final String classPath)
Extract the class name from the whole class path
int index = classPath.lastIndexOf('/');
if (index < 0) {
    index = classPath.lastIndexOf('.');
if (index >= 0) {
    return classPath.substring(index + 1);
return classPath;
...
StringextractClassName(final String fullClassName)
Extract the name of a class from the full name (includes packages).
return extractClassNameWithGeneric(fullClassName).replaceAll("<(.*)>", "");
StringextractClassName(String fullClassName)
extract Class Name
if (fullClassName == null)
    return null;
int index = fullClassName.lastIndexOf(".");
if (index > 0) {
    return fullClassName.substring(index + 1, fullClassName.length());
} else {
    return fullClassName;
StringextractClassName(String fullElement)
extract Class Name
return fullElement.substring(0, fullElement.lastIndexOf("."));
StringextractClassName(String fullyQualifiedClassName)
Extracts class name from a fully qualified class name For example, when 'org.wso2.developerStudio.Test' is given as an argument, it will return 'Test'
int lastIndexOfDot = fullyQualifiedClassName.lastIndexOf(DOT_SEPARATOR);
return fullyQualifiedClassName.substring(++lastIndexOfDot, fullyQualifiedClassName.length());
StringextractClassName(String javaSource)
Extract the class name of the Java source code
javaSource = javaSource.replaceAll("\t", "    ");
int classIndex = javaSource.indexOf("class ");
if (classIndex == -1)
    throw new IllegalArgumentException("Is not a class!");
int bracketIndex = javaSource.indexOf('{', classIndex);
if (bracketIndex == -1)
    throw new IllegalArgumentException("{ not after class");
classIndex += "class ".length();
...
StringextractClassName(String methodName)
Extracts the class name from a method name.
try {
    String className = methodName.substring(0, methodName.indexOf('('));
    className = className.substring(0, className.lastIndexOf('.'));
    if (className.indexOf(' ') >= 0) {
        className = className.substring(className.lastIndexOf(' ') + 1, className.length());
    return className;
} catch (Exception e) {
...
StringextractClassName(String qualifiedName)
Extracts the name of a class from the qualified class name.
int index = qualifiedName.lastIndexOf('.');
String name = qualifiedName;
if (index >= 0) {
    name = qualifiedName.substring(index + 1);
return name;
StringextractClassNameFromArray(final String arrayName)
Extract a class name from an array.
String cName = arrayName;
if (arrayName.contains("<")) {
    cName = arrayName.substring(arrayName.indexOf('<') + 1, arrayName.indexOf('>'));
} else if (arrayName.contains("[]")) {
    cName = arrayName.substring(0, arrayName.indexOf('['));
return cName;
String[]extractClassNames(Class[] classArray)
extract Class Names
String[] array = new String[classArray.length];
for (int i = 0; i < classArray.length; i++) {
    array[i] = classArray[i].getName();
return array;