Java Collections create empty ListIterator

Description

Java Collections create empty ListIterator

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

public class Main {

   public static void main(String[] args) {
      ListIterator<String> it = returnEmptyListIterator();
      /*from www . j a  v  a2 s.  co m*/
   }
   public static <T> ListIterator<T> returnEmptyListIterator() {
      boolean someConditionMet = false;
      if(someConditionMet) {
          ArrayList<T> list = new ArrayList<>();
          // Add elements
          ListIterator<T> listIterator = list.listIterator();
          return listIterator;
      } else {
          return Collections.emptyListIterator();
      }
  }
}



PreviousNext

Related