Here you can find the source of stringMemoryUsedInMB()
public static String stringMemoryUsedInMB()
//package com.java2s; // Licensed under the terms of the New BSD License. Please see associated LICENSE file for terms. public class Main { public static final long MEGA = 1048576; /**//from ww w . j a va 2 s.co m * Returns the amount of memory currently used by the JVM, in megabytes, as a string. */ public static String stringMemoryUsedInMB() { String ret = String.format("%,d MB", memoryUsedInMB()); return ret; } /** * Returns the amount of memory currently used by the JVM, in megabytes. */ public static long memoryUsedInMB() { return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / MEGA; } }