-2
import java.util.*;   

public class Main
{
  public static void main(String[] args) 
  {
      List student = new ArrayList();
      student.add("123");
      student.add("ABC");
      student.add("70.8");    

      Iterator itr = listItr.iterator();

      while(itr.hasNext())      
      {
          System.out.println(itr.next()); 

      }
 }  

} What should i write here Iterator itr = _________; in order to get an output?

2 Answers2

0

You are trying to iterate over nothing :

// specify a list type with <yourType>
List<String> students=new ArrayList<String>();
// fill up your list

// was Iterator it = listItr.iterator(); but listItr is nothing
Iterator<String> it=students.iterator();
while(it.hasNext()) {
    System.out.println(it.next());
}
midugh
  • 608
  • 5
  • 21
0

Generics aside, you only have to change this line:

Iterator itr = listItr.iterator();

to this:

Iterator itr = student.iterator();
Jason
  • 11,744
  • 3
  • 42
  • 46