public static String getClassName ( final Class < ? > clazz ) { final String fullName = clazz . getName ( ) ; final int fullNameLength = fullName . length ( ) ; // Check for array ('[') or the class/interface marker ('L') ... int numArrayDimensions = 0 ; while ( numArrayDimensions < fullNameLength ) { final char c = fullName . charAt ( numArrayDimensions ) ; if ( c != ' ' ) { String name = null ; // Not an array, so it must be one of the other markers ... switch ( c ) { case ' ' : { name = fullName . subSequence ( numArrayDimensions + 1 , fullNameLength ) . toString ( ) ; break ; } case ' ' : { name = "byte" ; break ; } case ' ' : { name = "char" ; break ; } case ' ' : { name = "double" ; break ; } case ' ' : { name = "float" ; break ; } case ' ' : { name = "int" ; break ; } case ' ' : { name = "long" ; break ; } case ' ' : { name = "short" ; break ; } case ' ' : { name = "boolean" ; break ; } case ' ' : { name = "void" ; break ; } default : { name = fullName . subSequence ( numArrayDimensions , fullNameLength ) . toString ( ) ; } } if ( numArrayDimensions == 0 ) { // No array markers, so just return the name ... return name ; } // Otherwise, add the array markers and the name ... if ( numArrayDimensions < BRACKETS_PAIR . length ) { name = name + BRACKETS_PAIR [ numArrayDimensions ] ; } else { for ( int i = 0 ; i < numArrayDimensions ; i ++ ) { name = name + BRACKETS_PAIR [ 1 ] ; } } return name ; } ++ numArrayDimensions ; } return fullName ; }
Returns the name of the class . The result will be the fully - qualified class name or the readable form for arrays and primitive types .