这篇文章主要介绍了java 中遍历取值异常(hashtable enumerator)解决办法的相关资料,用迭代器取值时抛出的异常:java.util.nosuchelementexception: hashtable enumerator ,需要的朋友可以参考下
Java中遍历取值异常报错的解决办法
用迭代器取值时抛出的异常:java.util.NoSuchElementException: Hashtable Enumerator
示例代码
//使用迭代器遍历
Iterator<String> it = tableProper.stringPropertyNames().iterator();
sqlMap = new HashMap<String,String>();
while(it.hasNext()){
sqlMap.put(it.next(), tableProper.getProperty(it.next()));
} 这是一个枚举异常,是因为在还没来得及执行it.next()时就开始引用它。我们可以用如下方式解决此问题:
立即学习“Java免费学习笔记(深入)”;
//使用迭代器遍历
Iterator<String> it = tableProper.stringPropertyNames().iterator();
sqlMap = new HashMap<String,String>();
String key;
while(it.hasNext()){
key = it.next();
sqlMap.put(key, tableProper.getProperty(key));
}以上就是Java中遍历取值异常报错的解决办法的详细内容,更多请关注php中文网其它相关文章!
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号