Java-class name

Please tell me how to compare the class name with the specified string( the string is entered by the user). Is there any way to write the class name to a string variable?

Author: Clegan, 2013-12-24

1 answers

Well, of course you can.

String name = MyClass.class.getName();

Or

String name = MyClass.class.getSimpleName();

Then there will be a short class name, without the package name. Or so:

MyClass my = new MyClass();
String name = my.getClass().getName();
 9
Author: Vladislav Pyatkov, 2013-12-24 18:14:54