<%
  Hashtable test1 = new Hashtable();
  Hashtable test2 = new Hashtable();
  Hashtable all = new Hashtable();
  test1.put("A","第一列");
  test1.put("B","第二列");
  all.put("FIRST",test1);
  test2.put("1","No1");
  test2.put("2","No2");
  test2.put("3","No3");
  all.put("SECOND",test2);
  out.println("all.size = "+all.size()+"<br>");
  Hashtable check = (Hashtable)all.get("FIRST");
  out.println("first.size = "+check.size()+"<br>");
  Hashtable check1 = (Hashtable)all.get("SECOND");
  out.println("second.size = "+check1.size()+"<br>");
%>
运行结果应该是all.size = 2
first.size = 2  
second.size = 3我想问题出在test1上,有可能都指向test1,才得出
all.size = 2
first.size = 3
second.size = 3

解决方案 »

  1.   

    test1.clear();
    会清除所有内容
      

  2.   

    try:<%@page import="java.util.*"%><%
      Hashtable test1 = null ;
      Hashtable all = new Hashtable();
      test1 = new Hashtable() ;
      test1.put("A","第一列");
      test1.put("B","第二列");
      all.put("FIRST",test1);
      test1 = new Hashtable() ;
      test1.put("1","No1");
      test1.put("2","No2");
      test1.put("3","No3");
      all.put("SECOND",test1);
      out.println("all.size = "+all.size()+"<br>");
      Hashtable check = (Hashtable)all.get("FIRST");
      out.println("first.size = "+check.size()+"<br>");
      Hashtable check1 = (Hashtable)all.get("SECOND");
      out.println("second.size = "+check1.size()+"<br>");
    %>