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. android 百度最新地图sdk包怎么去除 放大缩小按钮

    // 隐藏缩放控件 int childCount = mMapView.getChildCount(); View zoom = null; ; i < childCount; i++) { V ...

  2. MVC 优缺点

    MVC是一个架构,或者说是一个设计模式,它就是强制性使应用程序的输入,处理和输出分开.将一个应用程序分为三个部分:Model,View,Controller. 1. MVC的优点 (1) 可以为一个模 ...

  3. jQuery 自学笔记—3

    jQuery 语法实例 $(this).hide() 演示 jQuery hide() 函数,隐藏当前的 HTML 元素. $("#test").hide() 演示 jQuery ...

  4. Java编程思想重点笔记

    首先声明转自https://github.com/lanxuezaipiao/ReadingNotes 无意中发现,写的蛮好转过来学习下. 1. Java中的多态性理解(注意与C++区分) Java中 ...

  5. struts2自己定义类型转换器

    1.1.  struts2自己定义类型转换器 1)        自定类型转换类,继承DefaultTypeConverter类 package com.morris.ticket.conversio ...

  6. STL之使用vector排序

    应用场景: 在内存中维持一个有序的vector: // VectorSort.cpp : Defines the entry point for the console application. #i ...

  7. python开发环境安装

    1.首先安装python-3.4.2.msi,此为python主程序,双击安装,根据自身的情况做选择,也可以使用默认设置,一路next也没什么问题. 2.设置环境变量=>编辑Path,在最后加上 ...

  8. [译]Stairway to Integration Services Level 8 - SSIS 工作流管理高级

    介绍 在前两个章节我们,建立了一个新的SSIS包,简单的使用了一下scripting还有优先约束,并且测试了MaxConcurrentExecutables 属性.  同时实验了  “On Succe ...

  9. SpringMVC 详解

    一.SpringMVC基础入门,创建一个HelloWorld程序 1.首先,导入SpringMVC需要的jar包. 2.添加Web.xml配置文件中关于SpringMVC的配置 1 2 3 4 5 6 ...

  10. CGI PHP安装

    ./configure --with-php-config=/usr/local/php/bin/php-config--with-pdo-mysql=/usr/local/mysql PDO——MY ...