用员工信息表作为实例
源代码:
Info类:
public class Info {
private int key;
private String name;
public Info(int key ,String name) {
// TODO Auto-generated constructor stub
this.key = key;
this.name = name;
}
public int getKey() {
return key;
}
public void setKey(int key) {
this.key = key;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
HashTable类:
public class hashTable {
private Info[] array; //员工信息数组
//构造方法
public hashTable() {
// TODO Auto-generated constructor stub
array = new Info[100];
}
//重载构造方法
public hashTable(int MaxSize)
{
array = new Info[MaxSize];
}
//插入数据
public void insert(Info info)
{
array[info.getKey()] = info;
}
//查找数据
public Info find(int key)
{
return array[key];
}
}