首页 > 其他 > 详细

Hashtable的用法

时间:2021-07-07 12:53:24      阅读:26      评论:0      收藏:0      [点我收藏+]

3.3 Hashtable的用法  

马克-to-win:假如我们想把张三20岁,李四30岁这样的信息存入一个容器, 将来一查张三多少岁, 立刻能出来, 就用到Hashtable,张三---->20,就是一个键值对。

例:3.3.1

import java.io.*;
import java.util.*;

class TestMark_to_win {
    public static void main(String args[]) {
        Hashtable n = new Hashtable();
        n.put("thre", new Integer(3));
        n.put("for", new Integer(4));
        n.put("two", new Integer(2));
        n.put("one", new Integer(1));
        Integer n0 = (Integer) n.get("twotwo");
        if (n0 != null) {
            System.out.println("won‘t print = " + n0);
        }

        Integer m = (Integer) n.get("two");
        if (m != null) {
            System.out.println("two = " + m);
        }
        Enumeration e = n.elements();
        while (e.hasMoreElements()) {
            System.out.println(e.nextElement());
        }
        Enumeration ke = n.keys();
        while (ke.hasMoreElements()) {
            System.out.println(ke.nextElement());
        }
    }
}
 

更多内容请见原文,原文转载自:https://blog.csdn.net/qq_43650923/article/details/101597949

Hashtable的用法

原文:https://www.cnblogs.com/xiaolongxia1922/p/14979993.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!