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.
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.
相关考题:
现有: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();)
1.importjava.util.*;2.classForInTest{3.staticListlist=newArrayList();4.5.staticListgetList(){returnlist;}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(charo:list)B.for(Objecto:getList())C.for(Objecto:getList();)D.for(Objecto:o.getList())
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();)
现有:1.importjava.util.*; 现有:1.importjava.util.*;2.classForInTest{3.staticListlist-newArrayList():4.5.staticListgetList(){returnlist;}6.7.publicstaticvoidmain(Strincj[]args){8.list.add(a);list.add(b);list.add(c);9.//insertcodehere10.System.out.print(o);11.}12.}第9行插入哪一项将输出abc?()
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.
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.
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.
现有: 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 (); )
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.
10. interface A { void x(); } 11. class B implements A { public void x() { } public voidy() { } } 12. class C extends B { public void x() {} } And: 20. java.util.List list = new java.util.ArrayList(); 21. list.add(new B()); 22. list.add(new C()); 23. for (A a:list) { 24. a.x(); 25. a.y();; 26. } What is the result?() A、 The code runs with no output.B、 An exception is thrown at runtime.C、 Compilation fails because of an error in line 20.D、 Compilation fails because of an error in line 21.E、 Compilation fails because of an error in line 23.F、 Compilation fails because of an error in line 25.
现有: 3. import java.util.*; 4. class ForInTest { 5.static List list=new ArrayList(); 6. 7.public static void main (String [] args) { 8.list. add("a"); list. add("b");list. add( "c"); 9. //insert code here 10. System.out.print (o); 11. } 12. } 哪一行插入到第9行将导致输出“abc"?() A、 for (Iterator o : list.iterator(); o.hasNext (); )B、 for (Iterator 0 : list)C、 for (Object o : list.iterator())D、 for (Object o : list)
public static void search(List list) { list.clear(); list.add(”b”); list.add(”a”); list.add(”c”); System.out.println(Collections.binarySearch(list, “a”)); } What is the result of calling search with a valid List implementation?()A、0B、1C、aD、bE、cF、The result is undefined.
现有: - list是一个合法的集合引用 - getCollection()返回一个合法集合的引用 哪两个是合法的?() A、 for(Object o ; list)B、 for(Object o : getCollection()C、 for(Object o : list.iterator()D、 for(lterator i ; list.iterator() ; i.hasNext () )E、 for(lterator i=list.iterator(); i.hasNext (); )
- list 是一个合法的集合引用 - getCollection() 返回一个合法集合的引用 哪两个是合法的()A、for(Object o ; list)B、for(Object o : list.iterator())C、for(Object o : getCollection())D、for(Iterator i = list.iterator(); i.hasNext (); )
1. import java.util.*; 2. class ForInTest { 3. static List list = new ArrayList(); 4. 5. static List getList() { return list; } 6. 7. public static void main(String [] args) { 8. list.add("a"); list.add("b"); list.add("c"); 9. // insert code here 10. System.out.print(o); 11. } 12. } 第 9 行插入哪一项将输出 abc?() A、for(char o: list)B、for(Object o: getList())C、for(Object o: getList();)D、for(Object o: o.getList())
现有: 1. import java.util.*; 2. class ForInTest { 3.static List list - new ArrayList(): 4. 5.static List getList() { return list; } 6. 7.public static void main (Strincj[] args) { 8.list.add("a"); list.add("b"); list.add("c"); 9. //insert code here 10. System.out.print (o); 11. } 12. } 第9行插入哪一项将输出abc?() A、 for(char o: list)B、 for (Object o: o.getList())C、 for(Object o: getList();)D、 for(Object o: getList())E、 for(Object o: o.getList();)
1. import java.util.*; 2. public class Test { 3. public static void main(String[] args) { 4. List strings = new ArrayList(); 5. // insert code here 6. } 7. } Which four, inserted at line 5, will allow compilation to succeed?()A、 String s = strings.get(0);B、 Iterator i1 = strings.iterator();C、 String[] array1 = strings.toArray();D、 Iterator i2 = strings.iterator();E、 String[] array2 = strings.toArray(new String[1]);F、 Iterator i3 = strings.iterator();
3. import java.util.*; 4. class ForInTest { 5. static List list = new ArrayList(); 6. 7. public static void main(String [] args) { 8. list.add("a"); list.add("b"); list.add("c"); 9. //insert code here 10. System.out.print(o); 11. } 12. } 哪一行插入到第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 (); )
11. public static void append(List list) { list.add(”0042”); } 12. public static void main(String[] args) { 13. List intList = new ArrayList(); 14. append(intList); 15. System.out.println(intList.get(0)); 16. } What is the result?() A、 42B、 0042C、 An exception is thrown at runtime.D、 Compilation fails because of an error in line 13.E、 Compilation fails because of an error in line 14.
多选题现有: - list是一个合法的集合引用 - getCollection()返回一个合法集合的引用 哪两个是合法的?()Afor(Object o ; list)Bfor(Object o : getCollection()Cfor(Object o : list.iterator()Dfor(lterator i ; list.iterator() ; i.hasNext () )Efor(lterator i=list.iterator(); i.hasNext (); )
单选题11. public static void append(List list) { list.add(”0042”); } 12. public static void main(String[] args) { 13. List intList = new ArrayList(); 14. append(intList); 15. System.out.println(intList.get(0)); 16. } What is the result?()A 42B 0042C An exception is thrown at runtime.D Compilation fails because of an error in line 13.E Compilation fails because of an error in line 14.
单选题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.
单选题现有: 3. import java.util.*; 4. class ForInTest { 5. static List list = new ArrayList(); 6. 7. public static void main(String [] args) { 8. list.add("a"); list.add("b"); list.add("c"); 9. //insert code here 10. System.out.print(o); 11. } 12. } 哪一行插入到第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 (); )
单选题1. import java.util.*; 2. class ForInTest { 3. static List list = new ArrayList(); 4. 5. static List getList() { return list; } 6. 7. public static void main(String [] args) { 8. list.add("a"); list.add("b"); list.add("c"); 9. // insert code here 10. System.out.print(o); 11. } 12. } 第 9 行插入哪一项将输出 abc?()Afor(char o: list)Bfor(Object o: getList())Cfor(Object o: getList();)Dfor(Object o: o.getList())
单选题1. import java.util.*; 2. class SubGen { 3. public static void main(String [] args) { 4. //insert code here 5. } 6. } class Alpha { } class Beta extends Alpha { } class Gamma extends Beta { } 和四段代码片段: s1. ArrayList〈? extends Alpha〉 list1 = new ArrayList〈Gamma〉(); s2. ArrayList〈Alpha〉 list2 = new ArrayList〈? extends Alpha〉(); s3. ArrayList〈? extends Alpha〉 list3 = new ArrayList〈? extends Beta〉(); s4. ArrayList〈? extends Beta〉 list4 = new ArrayList〈Gamma〉(); ArrayList〈? extends Alpha〉 list5 = list4; 哪些片段分别插入到第4行,可允许代码编译?()A只有s1B只有s3C只有s1和s3D只有s1和s4
单选题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.
单选题现有: 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 (); )