T
t.j
Unregistered / Unconfirmed
GUEST, unregistred user!
这是<thanking in java> 中的一个例子.
以下这两句出现错误.
private Vector keys=new Vector();
private Vector values=new Vector();
Vector不是在java类中集成的有吗?
以下是一个散列表的一个例子....包含有Vector()这个句柄.求解答之.
//AssocArray.java
import java.util.*;
public class AssocArray extends Dictionary{
private Vector keys=new Vector();
private Vector values=new Vector();
public int size(){return keys.size();}
public boolean isEmpty(){
return keys.isEmpty();
}
public Object put(Object key,Object value){
keys.addElement(key);
values.addElement(value);
return key;
}
public Object get(Object key){
int index=keys.indexof(key);
if(index==-1) return null;
return values.elementAt(index);
{
public Object remove(Object key){
int index=keys.indexOf(key);
if (index==-1) return null;
keys.removeElementAt(index);
Object returnval=values.elementAt(index);
values.removeElementAt(index);
return returnval;
}
public Enumeration keys(){
return keys.elements();
}
public Enumeration elements(){
return values.elements();
}
public static void main(String[] args){
AssocArray aa=new AssocArray();
for(char c='a';c<='z';c++)
aa.put(String.valueOf(c),String.valueOf(c).toUppercase());
char[] ca={'a','e','i','o','u'};
for(int i=0;i<ca.length;i++)
System.out.println("Uppercase:"+aa.get(String.valueOf(ca)));
}
}
以下这两句出现错误.
private Vector keys=new Vector();
private Vector values=new Vector();
Vector不是在java类中集成的有吗?
以下是一个散列表的一个例子....包含有Vector()这个句柄.求解答之.
//AssocArray.java
import java.util.*;
public class AssocArray extends Dictionary{
private Vector keys=new Vector();
private Vector values=new Vector();
public int size(){return keys.size();}
public boolean isEmpty(){
return keys.isEmpty();
}
public Object put(Object key,Object value){
keys.addElement(key);
values.addElement(value);
return key;
}
public Object get(Object key){
int index=keys.indexof(key);
if(index==-1) return null;
return values.elementAt(index);
{
public Object remove(Object key){
int index=keys.indexOf(key);
if (index==-1) return null;
keys.removeElementAt(index);
Object returnval=values.elementAt(index);
values.removeElementAt(index);
return returnval;
}
public Enumeration keys(){
return keys.elements();
}
public Enumeration elements(){
return values.elements();
}
public static void main(String[] args){
AssocArray aa=new AssocArray();
for(char c='a';c<='z';c++)
aa.put(String.valueOf(c),String.valueOf(c).toUppercase());
char[] ca={'a','e','i','o','u'};
for(int i=0;i<ca.length;i++)
System.out.println("Uppercase:"+aa.get(String.valueOf(ca)));
}
}