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.

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.


相关考题:

publicstaticvoidsearch(Listlist){list.clear();list.add(”b”);list.add(”a”);list.add(”c”);System.out.println(Collections.binarySearch(list,a”));}WhatistheresultofcallingsearchwithavalidListimplementation?()A.0B.1C.aD.bE.cF.Theresultisundefined.

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()));

publicvoidaddStrings(Listlist){12.list.add(”foo”);13.list.add(”bar”);14.}Whatmustyouchangeinthismethodtocompilewithoutwarnings?() A.addthiscodeafterline11:list=(List)list;B.changelines12and13to:list.add(”foo”);list.add(”bar”);C.changethemethodsignatureonline11to:publicvoidaddStrings(ListextendsStringlist){D.changethemethodsignatureonline11to:publicvoidaddStrings(ListsuperStringlist){E.Nochangesarenecessary.Thismethodcompileswithoutwarnings.

Given:Whichtwocodefragments,insertedindependentlyatline5,willcompilewithoutwarnings?() A.publicvoidaddStrings(Listlist){B.publicvoidaddStrings(ListStringlist){C.publicvoidaddStrings(List?superStringlist){D.publicvoidaddStrings(List?extendsStringlist){B,C

定义一个List对象list,使用ArrayList的构造方法进行初始化,并且要求list中必须全部存放Integer类型的对象,以下语句正确的是()。A.List list = new ArrayList<Integer>();B.List list = new ArrayList ();C.List<Integer> list = new ArrayList<Integer>();D.ArrayList<Integer> list = new List<Integer>();

5. 给定如下Java代码,可以填入横线处的代码是() public static void main(String[] args) { ________ list.addLast("001"); }A.List list = new ArrayList();B.List list = new List();C.ArrayList list = new ArrayList();D.LinkedList list = new LinkedList();

定义一个List对象list,使用ArrayList的构造方法进行初始化,并且要求list中必须全部存放Integer类型的对象,以下语句正确的是()。A.List list = new ArrayList ();B.List list = new ArrayList<Integer>();C.ArrayList<Integer> list = new List<Integer>();D.List<Integer> list = new ArrayList<Integer>();

现在需要对list类对象使用的逻辑运算符==重载,以下函数声明正确的是?A.list list::operator==(const list a);B.list list::operator==(const list a);C.bool list::operator==(const list a);D.bool list::operator==(const list a);

定义一个List对象list,使用ArrayList的构造方法进行初始化,并且要求list中必须全部存放Integer类型的对象,以下语句正确的是()。A.List list = new ArrayList ();B.List list = new ArrayList<Integer>();C.List<Integer> list = new ArrayList<Integer>();D.ArrayList<Integer> list = new List<Integer>();