java.util.NoSuchElementException
2014-12-01 19:14
471 查看
long totaltime=0;
long calltime=System.currentTimeMillis();
System.out.println("println1:"+calltime);
Set<String> words=new HashSet<String>();
words.add("sour");
words.add("sweet");
words.add("bitter");
words.add("spicy");
Iterator<String> witer=words.iterator();
for(int i=0;i<20;i++)
{
System.out.println(witer.next());
}
long calltime2=System.currentTimeMillis();
System.out.println("calltime2:"+calltime2);
totaltime=calltime2-calltime;
System.out.println("totaltime:"+totaltime);
很简单的一段代码 ,什么原因报java.util.NoSuchElementException??
---这类的异常表明 表明枚举中没有更多的元素。
ok结果出来了 因为集合中只有4个元素,而循环了20;超过了长度。
--修改为i<4 之后 输出结果如下:
println1:1417432431871
sour
sweet
spicy
bitter
calltime2:1417432431872
totaltime:1
long calltime=System.currentTimeMillis();
System.out.println("println1:"+calltime);
Set<String> words=new HashSet<String>();
words.add("sour");
words.add("sweet");
words.add("bitter");
words.add("spicy");
Iterator<String> witer=words.iterator();
for(int i=0;i<20;i++)
{
System.out.println(witer.next());
}
long calltime2=System.currentTimeMillis();
System.out.println("calltime2:"+calltime2);
totaltime=calltime2-calltime;
System.out.println("totaltime:"+totaltime);
很简单的一段代码 ,什么原因报java.util.NoSuchElementException??
---这类的异常表明 表明枚举中没有更多的元素。
ok结果出来了 因为集合中只有4个元素,而循环了20;超过了长度。
--修改为i<4 之后 输出结果如下:
println1:1417432431871
sour
sweet
spicy
bitter
calltime2:1417432431872
totaltime:1
相关文章推荐
- 【JAVA学习】Iterator迭代器导致的java.util.NoSuchElementException原因与解决方法
- java.util.NoSuchElementException at java.util.AbstractList$Itr.next(AbstractList.java:350) at
- java.util.NoSuchElementException解决办法
- java中Exception in thread "main" java.util.NoSuchElementException
- 迭代器(Iterator)的java.util.NoSuchElementException错误的改正
- java.util.NoSuchElementException: No mapping for class sun.awt.AppContext
- java.util.NoSuchElementException: Timeout waiting for idle object
- Sqoop导入数据到MySql时的java.util.NoSuchElementException异常
- java.util.NoSuchElementException原因
- org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool exhausted和java.util.NoSuchElementException: Timeout wa
- java.util.NoSuchElementException错误 解决办法
- 异常处理系列:java.util.NoSuchElementException
- ibatis报错:Caused by: java.util.NoSuchElementException
- java.util.NoSuchElementException: Hashtable Enumerator
- java.util.NoSuchElementException解决办法
- 关于java.util.NoSuchElementException错误
- java.util.NoSuchElementException解决办法
- 错误 java.util.NoSuchElementException:Hashtable Enumerator
- Sqoop导入数据到MySql时的java.util.NoSuchElementException异常2
- java.util.NoSuchElementException解决办法