Java Collection Tutorial - 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  ww  w.  ja  v  a2s  .  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;
  }
}