importjava.util.*;
classKeyMaster{
publicinti;
publicKeyMaster(inti){this.i=i;}
publicbooleanequals(Objecto){returni==((KeyMaster)o).i;}
publicinthashCode(){returni;}
}
publicclassMapIt{
publicstaticvoidmain(String[]args){
Setset=newHashSet();
KeyMasterk1=newKeyMaster(1);
KeyMasterk2=newKeyMaster(2);
set.add(k1);set.add(k1);
set.add(k2);set.add(k2);
System.out.print(set.size()+:”);
k2.i=1;
System.out.print(set.size()+:”);
set.remove(k1);
System.out.print(set.size()+:”);
set.remove(k2);
System.out.print(set.size());
}
}
Whatistheresult?()
第1题
A.Strings=strings.get(0);
B.Iteratori1=strings.iterator();
C.String[]array1=strings.toArray();
D.Iterator
E.String[]array2=strings.toArray(newString[1]);
F.Iterator
第2题
A.42
B.0042
C.Anexceptionisthrownatruntime.
D.Compilationfailsbecauseofanerrorinline13.
E.Compilationfailsbecauseofanerrorinline14.
第3题
A.addthiscodeafterline11:list=(List
B.changelines12and13to:list.add
C.changethemethodsignatureonline11to:publicvoidaddStrings(List<extendsString>list){
D.changethemethodsignatureonline11to:publicvoidaddStrings(List<superString>list){
E.Nochangesarenecessary.Thismethodcompileswithoutwarnings.
第4题
1.publicclassTest{2.publicTfindLarger(Tx,Ty){3.if(x.compareTo(y)>0){4.returnx;5.}else{6.returny;7.}8.}9.}and:22.Testt=newTest();23.//insertcodehereWhichtwowillcompilewithouterrorswheninsertedatline23?()
A.Objectx=t.findLarger(123,“456”);
B.intx=t.findLarger(123,newDouble(456));
C.intx=t.findLarger(123,newInteger(456));
D.intx=(int)t.findLarger(newDouble(123),newDouble(456));
第5题
}}and:Drinkone=newDrink();Drinktwo=newDrink();one.name=Coffee”;two.name=Tea”;TreeSetset=newTreeSet();set.add(one);set.add(two);AprogrammeriteratesovertheTreeSetandprintsthenameofeachDrinkobject.Whatistheresult?()
A.Tea
B.Coffee
C.CoffeeTea
D.Compilationfails.
E.Thecoderunswithnooutput.
F.Anexceptionisthrownatruntime.
第6题
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()));
第7题
A.ListmyList=myArray.asList();
B.ListmyList=Arrays.asList(myArray);
C.ListmyList=newArrayList(myArray);
D.ListmyList=Collections.fromArray(myArray);
第8题
stem.out.println(Collections.binarySearch(list,a”));}WhatistheresultofcallingsearchwithavalidListimplementation?()
A.0
B.1
C.a
D.b
E.c
F.Theresultisundefined.
第9题
gs=newArrayList();strings.add(?aAaA”);strings.add(”AaA”);strings.add(?aAa”);strings.add(”AAaa”);Collections.sort(strings);for(Strings:strings){System.out.print(s+);}}}Whatistheresult?()
A.Compilationfails.
B.aAaAaAaAAaaAaA
C.AAaaAaAaAaaAaA
D.AaAAAaaaAaAaAa
E.aAaAaAaAaAAAaa
F.Anexceptionisthrownatruntime.
第10题
A.Collections.sort(a,a.reverse());intresult=Collections.binarySearch(a,“6”);
B.Comparatorc=Collections.reverseOrder();Collections.sort(a,c);intresult= Collections.binarySearch(a,“6”);
C.Comparatorc=Collections.reverseOrder();Collections.sort(a,c);intresult=Collections.binarySearch(a,“6”,c);
D.Comparatorc=Collections.reverseOrder(a);Collections.sort(a,c);intresult=Collections.binarySearch(a,“6”,c);
E.Comparatorc=newInverseComparator(newComparator());Collections.sort(a);intresult=Collections.binarySearch(a,“6”,c);
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!