I have this code which displays the allocated JVM memory in (I suppose) bytes:
Runtime.getRuntime().totalMemory()
When I print the output I get something like 12232313131
. Can you tell me how I can print this in megabytes and gigabytes?
I have this code which displays the allocated JVM memory in (I suppose) bytes:
Runtime.getRuntime().totalMemory()
When I print the output I get something like 12232313131
. Can you tell me how I can print this in megabytes and gigabytes?
A nice trick is to use printf(...);
System.out.printf("%.3fGiB", Runtime.getRuntime().totalMemory() / (1024.0 * 1024.0 * 1024.0));