Thursday, October 16, 2025
HomeLanguagesJavaJava Collections emptyIterator() Method with Examples

Java Collections emptyIterator() Method with Examples

The emptyIterator() method of Java Collections returns an iterator with no elements. This method is immutable. That is, we can not do any modifications after creating this method.

Syntax:

Iterator<data_type> object = Collections.emptyIterator();  

where,

  • data_type is the type of iterator object
  • object is the data to create an iterator

Parameters: It will accept no parameters.

Return Type: It will return an empty iterator.

Exceptions: It will not raise any exceptions.

Example 1:

Java




import java.util.*;
  
public class GFG {
  
    public static void main(String[] args)
    {
        // create an empty iteratoe
        Iterator<String> i = Collections.emptyIterator();
  
        // display the iterator
        System.out.println(i);
    }
}


Output

java.util.Collections$EmptyIterator@3d075dc0

Example 2:

Java




// Java program to display the next element
import java.util.*;
  
public class GFG {
  
    public static void main(String[] args)
    {
        // create an empty iteratoe
        Iterator<String> i = Collections.emptyIterator();
  
        // display the iterator next element
        System.out.println(i.hasNext());
    }
}


Output

false
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS