<script type="text/javascript"> google_ad_client = "pub-8800625213955058"; /* 336x280, 创建于 07-11-21 */ google_ad_slot = "0989131976"; google_ad_width = 336; google_ad_height = 280; // </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> 说明:我所涉及到的试验代码,均是针对于1百万条记录,我的硬件配置如下:CPUP4 1.5G,256M DDR的内存。 如果要试验其代码,要采用这种方式运行:java -Xms128M -Xmx250M TestMap 1,对内存容量的要求 Map对象高于List。因为Map除了Value外还需要一个Object的Key,从而增大了Map的容量。试验代码如下: import java.util.*; public class TestMap { public static void main(String[] args) { System.out.println("begin>>>>>>>>>>>>>>"); long sm = Runtime.getRuntime().totalMemory(); System.out.println("Begin Memory :" sm); Map m = new Hashtable(); //LinkedList tmpList = new LinkedList(); for (int i=0;i<1000000;i ) { m.put("" i,"i=" i); //Integer integer = new Integer(i); //tmpList.add(integer); } long em = Runtime.getRuntime().totalMemory(); System.out.println("End Memory :" em); System.out.println("End-Start Memory :" (em - sm)); //walkList(tmpList); System.out.println("<<<<<<<<<<<<<<<
>>>>>>>>>>>>>"); long sm = Runtime.getRuntime().totalMemory(); System.out.println("Begin Memory :" sm); Map m = new Hashtable(); //LinkedList tmpList = new LinkedList(); for (int i=0;i<1000000;i ) { m.put("" i,"i=" i); //Integer integer = new Integer(i); //tmpList.add(integer); } long em = Runtime.getRuntime().totalMemory(); System.out.println("End Memory :" em); System.out.println("End-Start Memory :" (em - sm)); //walkList(tmpList); System.out.println("<<<<<<<<<<<<<<<
>>>>>>>>>>>>>"); long sm = Runtime.getRuntime().totalMemory(); System.out.println("Begin Memory :" sm); Map m = new Hashtable(); LinkedList tmpList = new LinkedList(); for (int i=0;i<1000000;i ) { //m.put("" i,"i=" i); tmpList.add("i=" i); } long em = Runtime.getRuntime().totalMemory(); System.out.println("End Memory :" em); System.out.println("End-Start Memory :" (em - sm)); //walkList(tmpList); System.out.println("<<<<<<<<<<<<<<<