public class Example { public static void main(String[] args) { ArrayList list = new ArrayList(); // 创建ArrayList集合 list.add("Tom"); // 向该集合中添加字符串 list.add("Jerry"); Iterator it = list.iterator(); //获取迭代器 it.next(); it.next(); System.out.println(it.next()); } } 运行以上程序,输出结果是( )
举一反三
- 阅读下列程序 public class Example { public static void main(String[] args) { ArrayList list = new ArrayList(); // 创建ArrayList集合 list.add("Tom"); // 向该集合中添加字符串 list.add("Jerry"); list.add("Donald"); for(ListIterator it = list.listIterator();it.hasNext();){ Object object = it.next(); if("Jerry".equals(object)){ it.set("Speike"); } } System.out.println(list); } } 程序的运行结果是( )
- 阅读下列程序publicclassExample{publicstaticvoidmain(String[]args){ArrayListlist=newArrayList();//创建ArrayList集合list.add("Tom");//向该集合中添加字符串list.add("Jerry");list.add("Donald");ListIteratorit=list.listIterator();while(it.hasNext()){Objectobject=it.next();if("Jerry".equals(object)){it.set("Speike");}}System.out.println(list);}}程序的运行结果是()
- 阅读代码,选择正确答案。 import java.util.*; public class TestListSet{ public static void main(String args[]){ List list = new ArrayList(); list.add(“Hello”); ist.add(“Learn”); list.add(“Hello”); list.add(“Welcome”); et set = new HashSet(); set.addAll(list); System.out.println(set.size()); } }
- public static void main(String[] args) { LinkedList list=new LinkedList(); list.add("A"); list.add("B"); String s=(String)list.get(2); System.out.println(s); } 编译运行的结果是
- public class Demo{ public static void main(String[] args){ List a1=new ArrayList(); a1.add(1); a1.add(2); a1.add(2); a1.add(3); System.out.println(a1); }}上述程序执行后的输出是( )