Created
October 28, 2017 18:37
-
-
Save javamultiplex/a462ebc539cad309da58a3ea0e6028b4 to your computer and use it in GitHub Desktop.
Example of IllegalStateException present in java.lang package.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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