6 Nov 2014

How to get the method name of the current method that is running in JAVA?

The following code helps you to identify what is the method that is being executed in JAVA at runtime:


StackTraceElement[] ste = Thread.currentThread().getStackTrace();
String strMethodName = ste[1].getMethodName(); // Get this method name

If you specify 2 in place of 1 in the second statement, it will give you the method that has called this method and so on in the stack.