Yes, in Java we do have a similar function called Thread.currentThread().getStackTrace();
This method will return you the array of StackTraceElement. The array returned gives the current stack trace. Below is a demo to implement this method:
public class TestDumpThread {
//Dump the current thread stack trace.
public static void dumpCurrentStackTrace() {
StackTraceElement[] stes = Thread.currentThread().getStackTrace();
for (StackTraceElement element : stes) {
System.out.println(element);
}
}
public static void main(String[] args) {
dumpCurrentStackTrace();
}
}
This will give you the below output:
java.lang.Thread.getStackTrace(Unknown Source)
DemoDumpThread.dumpCurrentStackTrace(DemoDumpThread.java:3)
DemotDumpThread.main(DemotDumpThread.java:10)