- Java.util Package Classes
- Java.util - Home
- Java.util - ArrayDeque
- Java.util - ArrayList
- Java.util - Arrays
- Java.util - BitSet
- Java.util - Calendar
- Java.util - Collections
- Java.util - Currency
- Java.util - Date
- Java.util - Dictionary
- Java.util - EnumMap
- Java.util - EnumSet
- Java.util - Formatter
- Java.util - GregorianCalendar
- Java.util - HashMap
- Java.util - HashSet
- Java.util - Hashtable
- Java.util - IdentityHashMap
- Java.util - LinkedHashMap
- Java.util - LinkedHashSet
- Java.util - LinkedList
- Java.util - ListResourceBundle
- Java.util - Locale
- Java.util - Observable
- Java.util - PriorityQueue
- Java.util - Properties
- Java.util - PropertyPermission
- Java.util - PropertyResourceBundle
- Java.util - Random
- Java.util - ResourceBundle
- Java.util - ResourceBundle.Control
- Java.util - Scanner
- Java.util - ServiceLoader
- Java.util - SimpleTimeZone
- Java.util - Stack
- Java.util - StringTokenizer
- Java.util - Timer
- Java.util - TimerTask
- Java.util - TimeZone
- Java.util - TreeMap
- Java.util - TreeSet
- Java.util - UUID
- Java.util - Vector
- Java.util - WeakHashMap
- Java.util Package Extras
- Java.util - Interfaces
- Java.util - Exceptions
- Java.util - Enumerations
- Java.util Useful Resources
- Java.util - Useful Resources
- Java.util - Discussion
Java Collections emptyListIterator() Method
Description
The Java Collections emptyListIterator() method is used to get the empty list iterator. ListIterator is empty and its hasNext method always returns false. next() method call throws NoSuchElementException and remove() throws IllegalStateException.
Declaration
Following is the declaration for Java Collections emptyListIterator() method.
public static <T> ListIterator<T> emptyListIterator()
Parameters
NA
Return Value
NA
Exception
NA
Getting Empty ListIterator of Integers Example
The following example shows the usage of Java Collection emptyListIterator() method to get an empty list iterator of Integers. We've created an empty list iterator using emptyListIterator() method and then checked if list iterator has elements or not.
package com.tutorialspoint; import java.util.Collections; import java.util.ListIterator; public class CollectionsDemo { public static void main(String args[]) { // create an empty list ListIterator<Integer> emptyListIterator = Collections.emptyListIterator(); System.out.println("Created empty list iterator, it has elements: "+emptyListIterator.hasNext()); } }
Output
Let us compile and run the above program, this will produce the following result.
Created empty list iterator, it has elements: false
Getting Empty ListIterator of Strings Example
The following example shows the usage of Java Collection emptyListIterator() method to get an empty list iterator of Strings. We've created an empty list iterator using emptyListIterator() method and then checked if list iterator has elements or not.
package com.tutorialspoint; import java.util.Collections; import java.util.ListIterator; public class CollectionsDemo { public static void main(String args[]) { // create an empty list ListIterator<String> emptyListIterator = Collections.emptyListIterator(); System.out.println("Created empty list iterator, it has elements: "+emptyListIterator.hasNext()); } }
Output
Let us compile and run the above program, this will produce the following result.Exception will be thrown as the list is immutable.
Created empty list iterator, it has elements: false
Getting Empty ListIterator of Objects Example
The following example shows the usage of Java Collection emptyListIterator() method to get an empty list iterator of Student objects. We've created an empty list iterator using emptyListIterator() method and then checked if list iterator has elements or not.
package com.tutorialspoint; import java.util.Collections; import java.util.ListIterator; public class CollectionsDemo { public static void main(String args[]) { // create an empty list ListIterator<Student> emptyListIterator = Collections.emptyListIterator(); System.out.println("Created empty list iterator, it has elements: "+emptyListIterator.hasNext()); } } class Student { int rollNo; String name; Student(int rollNo, String name){ this.rollNo = rollNo; this.name = name; } @Override public String toString() { return "[ " + this.rollNo + ", " + this.name + " ]"; } }
Output
Let us compile and run the above program, this will produce the following result.Exception will be thrown as the list is immutable.
Created empty list iterator, it has elements: false
To Continue Learning Please Login
Login with Google