Get the unqualified name of a class in Java
Description
The following code shows how to get the unqualified name of a class.
Example
//from w w w . j ava 2 s . c om
public class Main {
public static void main(String[] argv) throws Exception {
Class cls = java.util.Map.Entry.class;
String name = cls.getName();
System.out.println(name);
if (name.lastIndexOf('.') > 0) {
name = name.substring(name.lastIndexOf('.') + 1); // Map$Entry
System.out.println(name);
name = name.replace('$', '.'); // Map.Entry
System.out.println(name);
}
}
}
The code above generates the following result.