Java Utililty Methods Class Name Clean

List of utility methods to do Class Name Clean

Description

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

Method

StringclassNameFromQualifiedClassName(String qualifiedName)
Return only class name of a full qualified (package+classname) string.
if (qualifiedName == null) {
    throw new IllegalArgumentException("qualifiedName can't be null!");
int dot_index = qualifiedName.lastIndexOf('.');
if (dot_index != -1)
    return qualifiedName.substring(dot_index + 1);
else
    return qualifiedName;
...
StringclassNameFromQualifiedName(String qualifiedCalssName)
class Name From Qualified Name
qualifiedCalssName = qualifiedCalssName.replace('.', ':');
String[] parts = qualifiedCalssName.split(":");
if (parts.length == 0) {
    return "";
return parts[parts.length - 1];
StringclassNameOnly(Object o)
Given an Object instance, returns just the classname with no package
String s = "[null object ref]";
if (o != null) {
    s = classNameOnly(o.getClass().getName());
return s;
StringclassNameWithoutGeneric(String s)
class Name Without Generic
return removeGeneric(lastIdentifier(s));
StringclassNameWithoutPackage(Class objectClass)
Returns the name of a class with the package name cut off.
return classNameWithoutPackage(objectClass.getName());
StringclassNameWithoutPackage(Class objectClass)
class Name Without Package
return classNameWithoutPackage(objectClass.getName());
StringclassNameWithoutPackage(String classname)
class Name Without Package
String ret = classname;
final int i = classname.lastIndexOf('.');
if (i != -1) {
    ret = classname.substring(i + 1);
return ret;
StringclassNameWithoutPackageQualifiers(String className)
class Name Without Package Qualifiers
return className.substring(className.lastIndexOf(".") + 1);