자격증/OCJP_ExamC
QUESTION 24
IT grow.
2018. 7. 24. 02:54
반응형
QUESTION 24Given:import java.util.*;public class SortOf {public static void main(String[] args) {ArrayList<Integer> a = new ArrayList<Integer>();a.add(1);a.add(5);a.add(3);Collections.sort(a);a.add(2);Collections.reverse(a);System.out.println(a);}}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.Solution : C
plus imformation
Collections.Sort(a) --> 이 부분에서 정렬이 됩니다 . 특별한 조건이 없군요 . 숫자 순서대로 정렬이 됩니다 .
결과적으로 1 , 3 , 5 가 정렬이 될 겁니다 .
그 다음으로 2를 추가해 주었습니다 .
1 , 3 , 5 , 2 가 되겠습니다 .
마지막으로 reverse를 해 주었으므로 [ 2 ,5, 3, 1 ] 최종 값.
반응형