"SCJP 1.6版考題 205" 修訂間的差異
|   (新頁面: Given:  <br>12.  import java.util.*;  <br>13.  public class Explorer2{  <br>14.            public static void main(String[] args){  <br>15. &nbs...) | 
| (無差異) | 
於 2013年3月27日 (三) 17:02 的最新修訂
Given: 
12.  import java.util.*; 
13.  public class Explorer2{ 
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.                       s.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: E
 解說:
  從JDK:subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive) 
    
      第一個和第三個參數是取值的範圍,第二個和第四個參數是指出是否包含範圍的值 
 
	
| 
 | ||||||||||||||||||||
