SCJP題庫第214題

 
Given:
12. import java.util.*;
13. public class Explorer3{
14. public static void main(String[] args){
15.   TreeSet<Integer> s = new TreeSet<Integer>();
16.   TreeSet<Integer> subs = new TreeSet<Integer>();
17.   for(int i=606; i<613; i++)
18.     if(i%2 == 0) s.add(i);
19.   subs = (TreeSet)s.subSet(608, true, 611, true);
20.   subs.add(629);
21.   System.out.println(s + " " + subs);
22. }
23.}
What is the result?


A. Compilation fails.
B. An exception is thrown at runtime.
C. [608, 610, 612, 629] [608, 610]
D. [608, 610, 612, 629] [608, 610, 629]
E. [606, 608, 610, 612, 629] [608, 610]
F. [606, 608, 610, 612, 629] [608, 610, 629]
Ans: B

解說:
此題與205類似,僅差在20行,205題是s.adds,此題是subs.add
subss.subset產生出來的一個TreeSet,其有一個限制,就是做插入時,不能超過這個subSet範圍,此題範圍608~611
(請參考JDK說明 http://download.oracle.com/javase/6/docs/api/java/util/TreeSet.html#subSet(E, boolean, E, boolean) )

Comments

Popular posts from this blog

Android-使用webview在V3版的Google地圖GPS定位