Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

NoSuchElementException

/*
	NoSuchElementException is thrown when we try to access an element
    that does not exist in a list through an iterator, as illustrated below. 
*/

import java.util.ArrayList;
import java.util.List;

public class NoSuchElementExceptionDemo {
	public static void main(String[] args) {
		List<Integer> list = new ArrayList<>();

		// The below statement generates a NoSuchElementException
		// The iterator cannot access the non-existent element

		System.out.println(list.iterator().next());
	}
}
 
PREVIOUS NEXT
Tagged: #NoSuchElementException
ADD COMMENT
Topic
Name
1+3 =