Java Utililty Methods Class Name Create

List of utility methods to do Class Name Create

Description

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

Method

StringtoClassName(Class clazz)
to Class Name
return clazz == null ? null : clazz.getName().replace('$', '.');
StringtoClassName(Enum enumeration)
Pretvara oblik ime iz oblika "SOME_CONSTANT" u oblik "SomeConstant".
String name = enumeration.name();
StringBuffer s = new StringBuffer(name.length());
boolean lastUnderscore = true;
for (int i = 0; i < name.length(); ++i) {
    if (name.charAt(i) == '_') {
        lastUnderscore = true;
    } else {
        s.append(lastUnderscore ? name.charAt(i) : Character.toLowerCase(name.charAt(i)));
...
StringtoClassName(Object obj)
Returns the name of the class of the object in a short and readable form.
if (obj == null) {
    return toClassName(Void.class);
return toClassName(obj.getClass());
StringtoClassname(String apparatClassname)
to Classname
String cn = apparatClassname;
cn = cn.substring(cn.indexOf(';') + 1);
cn = cn.substring(0, cn.indexOf('.'));
cn = cn.replace('/', '.').replace('\\', '.').replace(';', '.');
return cn;
StringtoClassName(String className)
Converts a given string to a valid className (replaces backslashes with .)
if (null == className || className.isEmpty()) {
    return className;
if (className.startsWith(".") || className.startsWith("/")) {
    className = className.substring(1);
return className.replace("/", ".").replace("\\", ".");
StringtoClassName(String className)
to Class Name
char c = className.charAt(0);
String head = String.valueOf(c).toUpperCase();
return head + className.substring(1);
StringtoClassName(String className)
to Class Name
String name = className.replace('.', '/');
if (name.indexOf('$') < 0)
    return name;
String simpleName = getSimpleName(name);
if (simpleName.indexOf('$') < 0)
    return name;
int lastIndex = name.indexOf('$');
return name.substring(0, lastIndex);
...
StringtoClassName(String fileName)
to Class Name
String className = null;
if (fileName.endsWith(".class")) {
    int index = fileName.lastIndexOf('.');
    className = fileName.substring(0, index);
return className.replace('\\', '.');
StringtoClassName(String fileName)
Convert the Java-class-file-name to the equivalent Java-class-name (dot delimited package name).
StringBuffer className;
if (fileName == null) {
    throw new IllegalArgumentException("null 'fileName' arg in method call.");
fileName = fileName.trim();
if (fileName.equals("")) {
    throw new IllegalArgumentException("empty 'fileName' arg in method call.");
className = new StringBuffer(fileName);
if (fileName.endsWith(".class") && fileName.length() > 6) {
    className.setLength(className.length() - 6);
for (int i = 0; i < className.length(); i++) {
    if (className.charAt(i) == '/') {
        className.setCharAt(i, '.');
return className.toString();
StringtoClassName(String internalName)
Converts a class's internal name (i.e., using slashes) to Java source code format (i.e., using periods).
assert isNonBlank(internalName);
return internalName.replace('/', '.');