Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

How can I get the classname at runtime, but only the classname?

Writer Sebastian Wright

How can I get the classname at runtime, but only the actual classname and not the whole "com.xyz.etc." ?

I mean only the part of the name after the last period

2

2 Answers

You have to use this snippet code for object:

yourObject.getClass().getSimpleName();

or for class use :

yourClass.class.getSimpleName();

this code return only name of class, does not consist package name.

0
String className = object.getClass().getSimpleName(); 
0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy