我知道的也不太确切,只能简单说下我的理解。 hashtable(散列表)用于把范围很大的数字映射到较小的范围内,比如要给工厂职工发奖金,工厂有10000多职工但奖金只有20个人得,每个职工有个id号。要是用数组得定义大小为10000以上,然后person[1]=true;person[57]=true;...;person[9912]=true;等等。用hashtable就简单了,它就是存一些属性对,比如prizes.put("1",true);prizes.put("57",true);...省了不少空间。 把很大范围内的数散列到较小空间需要一定的方法,也就是散列函数,不同的散列函数有着不同的特性。常见的就是a%b这样的,b为散列空间的大小,但如果a的值有一定规律,比如正好都是n倍的b,那散列后的值就会集中到一起(产生很多碰撞)。为了解决散列碰撞,可以在碰撞后采取一定措施,比如向后移动一定距离等等。 没记错的话,HashTable类的散列函数是根据对象的hashcode值作为参数的。 Iterator是Enumeration类的代替品,说明如下: An iterator over a collection. Iterator takes the place of Enumeration in the Java collections framework. Iterators differ from enumerations in two ways: Iterators allow the caller to remove elements from the underlying collection during the iteration with well-defined semantics. Method names have been improved.
hashtable(散列表)用于把范围很大的数字映射到较小的范围内,比如要给工厂职工发奖金,工厂有10000多职工但奖金只有20个人得,每个职工有个id号。要是用数组得定义大小为10000以上,然后person[1]=true;person[57]=true;...;person[9912]=true;等等。用hashtable就简单了,它就是存一些属性对,比如prizes.put("1",true);prizes.put("57",true);...省了不少空间。
把很大范围内的数散列到较小空间需要一定的方法,也就是散列函数,不同的散列函数有着不同的特性。常见的就是a%b这样的,b为散列空间的大小,但如果a的值有一定规律,比如正好都是n倍的b,那散列后的值就会集中到一起(产生很多碰撞)。为了解决散列碰撞,可以在碰撞后采取一定措施,比如向后移动一定距离等等。
没记错的话,HashTable类的散列函数是根据对象的hashcode值作为参数的。
Iterator是Enumeration类的代替品,说明如下:
An iterator over a collection. Iterator takes the place of Enumeration in the Java collections framework. Iterators differ from enumerations in two ways: Iterators allow the caller to remove elements from the underlying collection during the iteration with well-defined semantics. Method names have been improved.
真诚的建议!别不给分啊:) '''
(0 0)
+-----oOO----(_)------------+
| |
| 有感而发! |
| |
| |
+------------------oOO------+
|__|__|
|| ||
ooO Ooo
好像是www.java-cn.com