jdk:http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Hashtable.html

  Hashtable numbers = new Hashtable();
numbers.put("one", new Integer(1));
numbers.put("two", new Integer(2));
numbers.put("three", new Integer(3));

To retrieve a number, use the following code:

     Integer n = (Integer)numbers.get("two");
if (n != null) {
System.out.println("two = " + n);
}

Enumeration keys()
    Returns an enumeration of the keys in this hashtable.

Set keySet()
           Returns a Set view of the keys contained in this Hashtable.
Object put(Object key, Object value)
  Maps the specified key to the specified value in this hashtable.

Collection values()
  Returns a Collection view of the values contained in this Hashtable.

Object clone()
  Creates a shallow copy of this hashtable.
boolean contains(Object value)
  Tests if some key maps into the specified value in this hashtable.
boolean containsKey(Object key)
  Tests if the specified object is a key in this hashtable.
boolean containsValue(Object value)
  Returns true if this Hashtable maps one or more keys to this value.

contains containskey区别,没什么区别,只不过containskey是很早以前的方法,contains是collection采用的方法。

官方说法:

contains:Note that this method is identical in functionality to containsValue, (which is part of the Map interface in the collections framework).

遍历方法:

1.

private static void test() {
Hashtable<String,String> table = new Hashtable<String,String>();
table.put("1", "hello");
table.put("2", "world!");
Iterator i = table.entrySet().iterator();
while(i.hasNext()){
Entry entry = (Entry) i.next();
System.out.println(entry.getKey()+"=>"+entry.getValue());
}
}

table.entrySet返回的是一个set集合。集合里的元素为Entry。

第二种方法:

public class Hashtable1 {
Hashtable<String,String> table=new Hashtable<String,String>(); public void retrieve()
{
table.put("1","hello");
table.put("2","world!"); Enumeration e=table.keys();
while(e.hasMoreElements())
{
Object elem=e.nextElement();
System.out.println(elem+"=>"+table.get(elem));
}
}

Enumeration遍历方法:

public interface Enumeration

An object that implements the Enumeration interface generates a series of elements, one at a time. Successive calls to the nextElement method return successive elements of the series.

For example, to print all elements of a vector v:

     for (Enumeration e = v.elements() ; e.hasMoreElements() ;) {
System.out.println(e.nextElement());
}

深入:

http://www.blogjava.net/fhtdy2004/archive/2009/07/03/285330.html

http://blog.csdn.net/teedry/article/details/4280034

java Hastable使用的更多相关文章

  1. Spark案例分析

    一.需求:计算网页访问量前三名 import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} /* ...

  2. java集合类

    1.Collection和Collections的区别? (1)Collection是一个接口,为集合对象的基本操作提供通用的接口放法. (2)Collections是一个工具类,里面包含各种对集合的 ...

  3. Java性能提示(全)

    http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.htmlComparing the performance of LinkedLi ...

  4. Java集合类操作优化总结

    清单 1.集合类之间关系 Collection├List│├LinkedList│├ArrayList│└Vector│ └Stack└SetMap├Hashtable├HashMap└WeakHas ...

  5. Java集合类操作优化经验总结

    本文首先针对 Java 集合接口进行了一些介绍,并对这些接口的实现类进行详细描述,包括 LinkedList.ArrayList.Vector.Stack.Hashtable.HashMap.Weak ...

  6. Java多线程基础总结

    一.线程和进程关系 二.创建方式1.继承Thread类,重写run方法2.实现Runable接口,重写run方法3.使用匿名内部类 三.API接口start()currentThread() 获取当前 ...

  7. JAVA之旅(二十九)——文件递归,File结束练习,Properties,Properties存取配置文件,load,Properties的小练习

    JAVA之旅(二十九)--文件递归,File结束练习,Properties,Properties存取配置文件,load,Properties的小练习 我们继续学习File 一.文件递归 我们可以来实现 ...

  8. 75道阿里Java面试题,你能答上几道?

    整理了下阿里近几年的java面试题目,大家参考下吧,希望对大家有帮助,可以帮大家查漏补缺. 答对以下这些面试题,可以淘汰掉 80 % 的求职竞争者. 1.hashcode相等两个类一定相等吗?equa ...

  9. 2018“金三”之一线互联网公司Java高级面试题总结

    JVM 1.请介绍一下JVM内存模型??用过什么垃圾回收器都说说呗 2.线上发送频繁full gc如何处理? CPU 使用率过高怎么办? 如何定位问题?如何解决说一下解决思路和处理方法 3.知道字节码 ...

随机推荐

  1. protel99se中做拼板图解

    很多时候我们要在protel99se中做拼板, 但是通常在复制进行拼版的时候会出现如下的效果,元件被重新命名了. 而无法达到我们需要的像下图的效果 那我们怎么办,才能达到上图的效果呢?其实操作很简单. ...

  2. spring boot 下 500 404 错误页面处理

    spring boot 作为微服务的便捷框架,在错误页面处理上也有一些新的处理,不同于之前的spring mvc 500的页面处理是比较简单的,用java config或者xml的形式,定义如下的be ...

  3. Book of Evil 树双向DFS

    Book of Evil Paladin Manao caught the trail of the ancient Book of Evil in a swampy area. This area ...

  4. Apache 错误代码配置

    ErrorDocument 400 /error_pages/400.htmlErrorDocument 401 /error_pages/401.htmlErrorDocument 403 /err ...

  5. js推断指定函数、变量是否存在的方法

    //推断是否存在指定函数 function isExitsFunction(funcName) { try { if (typeof (eval(funcName)) == "functio ...

  6. Enze frist day

    今天是我来到云和学院正式开班上课的第一天,我选择学习的科目是.net.因为.net我在学校的时候接触过一些,所以我想要更加深入的去学习.我觉得一个学生在学习上最怕的是没有遇到一位负责任的好老师,但幸运 ...

  7. Value Categories

    Value categories Three primary categories primary categories mixed special Each C++ expression (an o ...

  8. Servlet的学习笔记

    一.Servlet生命周期 init(ServletConfig config)  ----->初始化 service(ServletRequest req, ServletResponse r ...

  9. java 自定义BufferedReader_readLine

    import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import ...

  10. leetcode 15. 3Sum 双指针

    题目链接 给n个数, 找出三个数相加结果为0的所有的组, 不可重复. 用双指针的思想,O(n^2)暴力的找, 注意判重复. class Solution { public: vector<vec ...