public class T ... { public static void main(String[] args) throws Exception ...{ // 创建 1000 个 String String strA[] = new String[1000]; long start = 0; long end = 0; // 先垃圾回收 System.gc(); start = Runtime.getRuntime().freeMemory(); for (int i = 0; i < 1000; i ++) strA[i] = new String(); // 快要计算的时,再清理一次 System.gc(); end = Runtime.getRuntime().freeMemory(); System.out.println("一个String对象占内存:" + (start - end)/1000.0); } }