`
JsonLiangyoujun
  • 浏览: 828397 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

遍历取值异常(Hashtable Enumerator)

阅读更多
    用迭代器取值时抛出的异常: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()时就开始引用它。我们可以用如下方式解决此问题:
//使用迭代器遍历
			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));
			}

    原文永久地址:http://jsonliangyoujun.iteye.com/blog/2360983
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics