1.这段代码输出结果是?
ArrayList list = new ArrayList();
list.add("aA");
list.add("Aa");
Collections.sort(list);
System.out.println(list); 2.这段代码输出结果是?
import java.util.HashSet;
public class WrapString {
private String str="";
public WrapString(String str) {
this.str = str;
}
public static void main(String[] args) {
HashSet set = new HashSet();
set.add(new String("abc"));
set.add(new String("abc"));
set.add(new WrapString("sfd"));
set.add(new WrapString("sfd"));
System.out.println(set.size());
}
} 3.这段代码输出什么?
public static void main(String[] args) {
Object[] objs = {new String("foo"),new Integer(12),new Integer(5),new Boolean(true)};
Arrays.sort(objs);
for(Object obj:objs){
System.out.println(obj);
}
} 4.下边代码哪里有问题,指出问题代码。
package aa.bb;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
public class Test {
class A{}
class B extends A{}
public static void main(String[] args) {
List la = new LinkedList();
List lb = new LinkedList();
List lo = new LinkedList();
m1(la);
m1(lb);
m2(la);
m2(lb);
m1(lo);
m2(lo);
}
public static void m1(List extends A> list){}
public static void m2(List list){}
} 5.输出结果:
public static void main(String[] args) {
PriorityQueue pq = new PriorityQueue();
pq.add("carrot");
pq.add("apple");
pq.add("banana");
System.out.println(pq.poll() + "--" + pq.peek());
} 6.以下代码有无问题?
public class Test {
private N min,max;
public N getMin(){ return min;
}
public N getMax(){
return max;
}
public void add(N n){
if(n!=null && n.doubleValue()
if(n!=null && n.doubleValue()>max.doubleValue()) max=n;
}
}
public class Test换成
public class Test呢?
7.下边的结果是:
public class Test{
public static Collection getSort(){
Collection sort = new LinkedList();
sort.add("B");
sort.add("C");
sort.add("A");
return sort;
}
public static void main(String[] args) {
for(Object o:getSort()){
System.out.println(o);
}
}
} 8.下边代码的结果是:
public class Test{
public static void foo(List l ){
}
public static void main(String[] args) {
List l1 = new ArrayList();
foo(l1);
ArrayList l2 = new ArrayList();
foo(l2);
ArrayList l3 = new ArrayList();
foo(l3);
ArrayList l4 = new ArrayList();
foo(l4);
}
} 9.下边代码的结果是:
public class Test{
public static Object get0(List l){
return l.get(0);
}
public static void main(String[] args) {
String o1 = get0(new LinkedList());
Object o2 = get0(new LinkedList());
Object o3 = get0(new LinkedList());
Object o4 = get0(new LinkedList>());
String o5 = (String)get0(new LinkedList());
}
}
10.
public class Test{
enum Example{
ONE,TWO,THREE;
}
public static void main(String[] args) {
Collection c = new ArrayList();
c.add(Example.THREE);
c.add(Example.THREE);
c.add(Example.THREE);
c.add(Example.TWO);
c.add(Example.TWO);
c.add(Example.ONE);
Set set = new HashSet(c);
}
} 对这句
Set set = new HashSet(c)
代码描述正确的是:
A.The set variable contains all six elements from the coll collection, and the order is guaranteed to be preserved.
B. The set variable contains only three elements from the coll collection, and the order is guaranteed to be preserved.
C. The set variable contains all six elements from the coll collection, but the order is NOT guaranteed to be preserved. D. The set variable contains only three elements from the coll collection, but the order is NOT guaranteed to be preserved.
11.以下程序哪些句子可以1,2的输出结果?
public class Test{
public static void main(String[] args) {
//Set set = new TreeSet();
//Set set = new HashSet();
Set set = new LinkedHashSet();
set.add(2);
set.add(1);
System.out.println(set);
}
} 12.