Runtime run = Runtime.getRuntime();
long max = run.maxMemory()/(1024*1024);
long total = run.totalMemory()/(1024*1024);
long free = run.freeMemory()/(1024*1024);
long usable = max - total + free;
System.out.println("最大內存 = " + max);
System.out.println("已分配內存 = " + total);
System.out.println("已分配內存中的剩余空間 = " + free);
System.out.println("最大可用內存 = " + usable);
