Get Class name without package from StackTraceElement

KunLun :

I have this ste.getClassName() which return a String like this pack.age.Foo.

ste is StackTraceElement.

How I could get only Foo? Or the only way is to do a method which extract Foo from that string?

Mureinik :

There isn't a built in method for that. You could break up the string like @Naya and @Daniel Perez suggested, or let Class to the heavy lifting for you:

String simpleName = Class.forName(ste.getClassName()).getSimpleName();

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=115078&siteId=1