public static Iterator reverse(List list) {  Collections.rev

题目
单选题
public static Iterator reverse(List list) {  Collections.reverse(list);  return list.iterator();  }  public static void main(String[] args) {  List list = new ArrayList();  list.add(” 1”); list.add(”2”); list.add(”3”);  for (Object obj: reverse(list))  System.out.print(obj + “,”);  }  What is the result?()
A

 3,2,1,

B

 1,2,3,

C

 Compilation fails.

D

 The code runs with no output.

E

 An exception is thrown at runtime.

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

-list是一个合法的集合引用-getCollection()返回一个合法集合的引用哪两个是合法的()

A.for(Objecto;list)

B.for(Objecto:list.iterator())

C.for(Objecto:getCollection())

D.for(Iteratori=list.iterator();i.hasNext();)


参考答案:B, C

第2题:

Listlist=//morecodehere12.Collections.sort(list,newMyComparator());Whichcodewillsortthislistintheoppositeorderofthesortinline12?()

A.Collections.reverseSort(list,newMyComparator());

B.Collections.sort(list,newMyComparator());list.reverse();

C.Collections.sort(list,newInverseComparator(newMyComparator()));

D.Collections.sort(list,Collections.reverseOrder(newMyComparator()));


参考答案:D

第3题:

已知x为非空列表,那么表达式x.reverse()==list(reversed(x))的值为__________。


正确答案:False

第4题:

public class Alpha{  private static Character() ids;  public static void main( String[] args){  ids = new Character[args.length];  for (int i=0; iids[i] = new Character( args[i] );  System.out.print( ids[i] );  }  }  }   What is correct?()  

  • A、 Compilation fails.
  • B、 The code runs with no output.
  • C、 An exception is thrown at runtime.
  • D、 The code runs, outputing a concatenated list of the arguments passed to the program.

正确答案:A

第5题:

现有:   3.import java.util.*;   4.class ForInTest {   5.static List list = new ArrayList();  6.public static void main (String [] args){   7.  8.list.add("a"); list.add("b"); list.add("c");   9.//insert code here      10.System.out.print(o);  } }   哪一行插入到第9行将导致输出“abc”?() 

  • A、 for(Object o : list)
  • B、 for(Iterator o : list)
  • C、 for(Object o : list.iterator())
  • D、 for(Iterator o : list.iterator(); o.hasNext (); )

正确答案:A

第6题:

3.importjava.util.*;4.classForInTest{5.staticListlist=newArrayList();6.7.publicstaticvoidmain(String[]args){8.list.add("a");list.add("b");list.add("c");9.//insertcodehere10.System.out.print(o);11.}12.}哪一行插入到第9行将导致输出abc”?()

A.for(Objecto:list)

B.for(Iteratoro:list)

C.for(Objecto:list.iterator())

D.for(Iteratoro:list.iterator();o.hasNext();)


参考答案:A

第7题:

publicstaticIteratorreverse(Listlist){Collections.reverse(list);returnlist.iterator();}publicstaticvoidmain(String[]args){Listlist=newArrayList();list.add(”1”);list.add(”2”);list.add(”3”);for(Objectobj:reverse(list))System.out.print(obj+,”);}Whatistheresult?()

A.3,2,1,

B.1,2,3,

C.Compilationfails.

D.Thecoderunswithnooutput.

E.Anexceptionisthrownatruntime.


参考答案:C

第8题:

现有:3.importjava.util.*;4.classForInTest{5.staticListlist=newArrayList();6.publicstaticvoidmain(String[]args){7.8.list.add("a");list.add("b");list.add("c");9.//insertcodehere10.System.out.print(o);}}哪一行插入到第9行将导致输出abc”?()

A.for(Objecto:list)

B.for(Iteratoro:list)

C.for(Objecto:list.iterator())

D.for(Iteratoro:list.iterator();o.hasNext();)


参考答案:A

第9题:

11. public void addStrings(List list) {  12. list.add(”foo”);  13. list.add(”bar”);  14. }  What must you change in this method to compile without warnings?() 

  • A、 add this code after line 11: list = (List) list;
  • B、 change lines 12 and 13 to: list.add(”foo”); list.add(”bar”);
  • C、 change the method signature on line 11 to: public void addStrings(List< extends String> list) {
  • D、 change the method signature on line 11 to: public void addStrings(List< super String> list) {
  • E、 No changes are necessary. This method compiles without warnings.

正确答案:D

第10题:

11. List list = // more code here  12. Collections.sort(list, new MyComparator());  Which code will sort this list in the opposite order of the sort in line 12?() 

  • A、 Collections.reverseSort(list, new MyComparator());
  • B、 Collections.sort(list, new MyComparator()); list.reverse();
  • C、 Collections.sort(list, new InverseComparator( new MyComparator()));
  • D、 Collections.sort(list, Collections.reverseOrder( new MyComparator()));

正确答案:D

更多相关问题