Collectios public static ListIterator emptyListIterator() Method Example Program


Returns a list iterator that has no elements.

Program

package com.candidjava;

import java.util.Collections;
import java.util.ListIterator;

/**
 * 
 * @author karthikeyan.T
 * @description the following code shows how to use
 *              Collections.emptyListIterator() method.
 */

public class CollectionsEmptyListIterator {
	public static void main(String[] args) {

	}

	public static ListIterator getMy() {
		String nullFlag = null;
		if (nullFlag == null) {
			return Collections.emptyListIterator();
		}
		return null;
	}
}

Output



Explanation

public static ListIterator emptyListIterator()
Returns a list iterator that has no elements. More precisely,
hasNext and hasPrevious always return false.
next and previous always throw NoSuchElementException.
remove and set always throw IllegalStateException.
add always throws UnsupportedOperationException.
nextIndex always returns 0 .
previousIndex always returns -1.
Implementations of this method are permitted, but not required, to return the same object from multiple invocations.

Returns:
an empty list iterator
Since:
1.7


Related Post

Comments


©candidjava.com