SCJP題庫第203題

 
Given:
5. import java.util.*;
6. public class SortOf{
7.   public static void main(String[] args){
8.     ArrayList<Integer> a = new ArrayList<Integer>();
9.     a.add(1); a.add(5); a.add(3);
10.   Collections.sort(a);
11.   a.add(2);
12.   Collections.reverse(a);
13.   System.out.println(a);
14. }
15.}
What is the result?


A. [1, 2, 3, 5]
B. [2, 1, 3, 5]
C. [2, 5, 3, 1]
D. [5, 3, 2, 1]
E. [1, 3, 5, 2]
F. Compilation fails.
G. An exception is thrown at runtime.
Ans: C

解說:
串列加入順序1->5->3 使用Collections.sort排序之後變為1->3->5
加入2之後變為1->3->5->2 使用Collections.reverse反轉之後變為2->5->3->1

Comments

Popular posts from this blog

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