Skip to content

Instantly share code, notes, and snippets.

@javamultiplex
Created October 28, 2017 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javamultiplex/a462ebc539cad309da58a3ea0e6028b4 to your computer and use it in GitHub Desktop.
Save javamultiplex/a462ebc539cad309da58a3ea0e6028b4 to your computer and use it in GitHub Desktop.
Example of IllegalStateException present in java.lang package.
package com.javamultiplex.java.lang.exceptions;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
/**
* @author Rohit Agarwal
* @version 1.0
* @category java.lang/Exception
* @since JDK 1.1
*/
public class IllegalStateExceptionDemo {
public static void main(String[] args) {
String[] names = { "Rohit", "Bhavna", "Shivani" };
List<String> list = Arrays.asList(names);
Iterator<String> iterator = list.iterator();
while (iterator.hasNext()) {
/*
* IllegalStateException will be thrown because without getting any
* element we are removing it.
*/
iterator.remove();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment