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());
}
}
} 我应该在这里写Iterator itr = _________;为了得到一个 输出?
答案 0 :(得分:0)
您正在尝试迭代所有内容:
// 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());
}
答案 1 :(得分:0)
除泛型外,您只需要更改此行:
Iterator itr = listItr.iterator();
对此:
Iterator itr = student.iterator();