Java tutorial
//package com.java2s; public class Main { public static String printStackTrace(StackTraceElement[] stack) { StringBuilder output = new StringBuilder(1000); appendThreadStackTrace(output, stack); return output.toString(); } private static void appendThreadStackTrace(StringBuilder output, StackTraceElement[] stack) { for (StackTraceElement element : stack) { output.append("\t").append(element).append("\n"); } } }