HashtableAdd.java 589 B

123456789101112131415161718192021222324252627
  1. package samples.technology.reference;
  2. import java.util.*;
  3. public class HashtableAdd{
  4. public static void main(String[] args){
  5. Hashtable ht = new Hashtable();
  6. StringBuffer sb = new StringBuffer();
  7. sb.append("abc,");
  8. ht.put("1",sb);
  9. sb.append("def,");
  10. ht.put("2",sb);
  11. sb.append("mno,");
  12. ht.put("3",sb);
  13. sb.append("xyz.");
  14. ht.put("4",sb);
  15. int numObj=0;
  16. Enumeration it = ht.elements();
  17. while(it.hasMoreElements()){
  18. System.out.print("get StringBufffer "+(++numObj)+" from Hashtable: ");
  19. System.out.println(it.nextElement());
  20. }
  21. }
  22. }