example68hashapp.txt

来自「几个简单的java学习代码」· 文本 代码 · 共 42 行

TXT
42
字号
import java.util.*;

public class HashApp {

 public static void main(String[] args)  {

    Hashtable h= new Hashtable();
    h.put("height","6 feet" );
    h.put("weight","200 pounds");
    h.put("color","yellow");

    System.out.println("h:" + h);

    Enumeration e = h.keys();
    System.out.print("keys: ");
    while(e.hasMoreElements())
      System.out.print(e.nextElement()+",  ");

    System.out.print("\nelements: ");
    e = h.elements() ;
     while(e.hasMoreElements())
      System.out.print(e.nextElement()+", ");
    System.out.println();

    System.out.println("height: " +h.get("height"));
    System.out.println("weight: " +h.get("weight"));
    System.out.println("color: " +h.get("color"));

    h.remove("height");
    System.out.println("h:" + h);


 }
}


运行结果:

h:{height=6 feet, color=yellow, weight=200 pounds}keys: height,  color,  weight,  
elements: 6 feet, yellow, 200 pounds, height: 6 feetweight: 200 poundscolor: yellowh:{color=yellow, weight=200 pounds}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?