Getting a Class Name

Class c = someObject.getClass();
											String s = c.getName();

Getting the name of a Class object is an easy task. You get the class name of any Class object using the getName() method. The String returned by the getName() method will be the fully qualified class name. So for example, if in this phrase, the someObject variable is an instance of the String class, the name returned from the call to getName() will be

java.lang.String

Get Java™ Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.