Home Java Java-exception Example to show Iterator exception in java
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Example to show Iterator exception in java

Advertisement
Here we are describing the use of using exception class in java .This tutorial describes the way to handle Iterator exceptions appropriately in your programs and designs.

Example to show Iterator exception in java

     

Here we are describing the use of using exception class in java .This tutorial describes the way to handle Iterator exceptions appropriately in your programs and designs. The steps involved in the program are described below:-

IteratorException.java


import java.util.*;

public class IteratorException {

  public static void main(String[] args) {
  try {
  ArrayList List = new ArrayList();
  List.add("1");
  List.add("2");
  List.add("3");
  List.remove("34");

  Iterator itr = List.iterator();
  while (itr.hasNext()) {
  System.out.println(itr.next());
  }
  System.out.println(itr.next());
  catch (Exception ex) {
  System.out.println(ex);
  }
  }
}

 

Output of the program

1
2
3
java.util.NoSuchElementException


Download source code

 

Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 24, 2008

Ask Questions?    Discuss: Example to show Iterator exception in java  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com