Runtime.maxMemory(); //Z大JVM内存(就是你配置给JVM的值)
Runtime.totalMemory();//JVM可支配的Z大内存值
Runtime.freeMemory();//剩余内存空间
另外给一个例子:
Runtime run = Runtime.getRuntime();
long max = run.maxMemory();
long total = run.totalMemory();
long free = run.freeMemory();
long usable = max - total + free;
System.out.println("Z大内存 = " + max);
System.out.println("已分配内存 = " + total);
System.out.println("已分配内存中的剩余空间 = " + free);
System.out.println("Z大可用内存 = " + usable);
程序使用:java.lang.Runtime 包,不需要特别下载和导入