Collectios public static Iterator emptyIterator() Method Example Program


Returns an iterator that has no elements.

Program

package com.candidjava;
/**
 * @author karthikeyan.T
 * @description EmptyIterator is an iterator which is empty.
 */

import java.util.Collections;
import java.util.Iterator;

public class CollectionsEmptyIterator implements Iterator {

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

Output



Explanation

public static <T> Iterator<T> emptyIterator()
Returns an iterator that has no elements. More precisely,
hasNext always returns false.
next always throws NoSuchElementException.
remove always throws IllegalStateException.
Implementations of this method are permitted, but not required, to return the same object from multiple invocations.

Returns:
an empty iterator
Since:
1.7


Related Post

Comments


©candidjava.com