Java Collections.emptyIterator()

Syntax

Collections.emptyIterator() has the following syntax.

public static <T> Iterator <T> emptyIterator()

Example

In the following code shows how to use Collections.emptyIterator() method.


import java.util.Collections;
import java.util.Iterator;
//from  w w  w.  j  a va  2 s .  c o m
public class Main {

  public static void main(String[] args) {
  
  }
  public static Iterator getMy(){
    String nullFlag = null;
    if(nullFlag == null){
      return Collections.emptyIterator();
    }
    return null;
  }
}