下面代码的执行结果是?
import java.util.*;
public class ShortSet{
public static void main(String args[])
{
Set<Short> s=new HashSet<Short>();
for(Short i=0;i<100;i++)
{
s.add(i);
s.remove(i-1);
}
System.out.println(s.size());
}
}
A.1
B.100
C.Throws Exception
import java.util.*;
public class ShortSet{
public static void main(String args[])
{
Set<Short> s=new HashSet<Short>();
for(Short i=0;i<100;i++)
{
s.add(i);
s.remove(i-1);
}
System.out.println(s.size());
}
}
A.1
B.100
C.Throws Exception
D.None of the Above
解答:B
i是Short类型 i-1是int类型,其包装类为Integer,所以s.remove(i-1);不能移除Set集合中Short类型对象。