Hashtable ht=new Hashtable();
ht.put("1",11);
ht.put("2",22);
ht.put("3",33);
isExisUser("1"); //居然报错,真气人呀 public boolean isExisuser(String name)//根据一个名字判断是否在集合里面
{
Enumeration e=ht.keys();
while(e.hasMoreElements())
{
System.out.println(e.nextElement());
if(e.nextElement().equals(name))
return true;
}
return false;
}
ht.put("1",11);
ht.put("2",22);
ht.put("3",33);
isExisUser("1"); //居然报错,真气人呀 public boolean isExisuser(String name)//根据一个名字判断是否在集合里面
{
Enumeration e=ht.keys();
while(e.hasMoreElements())
{
System.out.println(e.nextElement());
if(e.nextElement().equals(name))
return true;
}
return false;
}
可以考虑用HashMap代替HashTable,然后return map.containsKey("1")不就好了containsKey
public boolean containsKey(Object key)Returns true if this map contains a mapping for the specified key. Specified by:
containsKey in interface Map
Overrides:
containsKey in class AbstractMap
Parameters:
key - The key whose presence in this map is to be tested
Returns:
true if this map contains a mapping for the specified key.
不好意思.
后来我才发现是这里错了.
System.out.println(e.nextElement()(问题在这里我又往下移了下));
if(e.nextElement().equals(name))
return true;
所以下面就报了个枚举超出.zhigangsun(流星) 说的很对.后来我才发现.有这个方法..
我是个新手.刚学J2ee.不过为期也就一个月.希望以后能碰到你们.