nerdexam
Oracle

1Z0-851 · Question #4

Given: import java.util.*; public class Explorer2 { public static void main(String[] args) { TreeSet<Integer> s = new TreeSet<Integer>(); TreeSet<Integer> subs = new TreeSet<Integer>(); for(int i =…

The correct answer is E. [606, 608, 610, 612, 629] [608, 610]. See the full explanation below for the reasoning.

Question

Given: import java.util.*; public class Explorer2 { public static void main(String[] args) { TreeSet<Integer> s = new TreeSet<Integer>(); TreeSet<Integer> subs = new TreeSet<Integer>(); for(int i = 606; i < 613; i++) if(i%2 == 0) s.add(i); subs = (TreeSet)s.subSet(608, true, 611, true); s.add(629); System.out.println(s + " " + subs); } } What is the result?

Options

  • ACompilation fails.
  • BAn 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]

How the community answered

(24 responses)
  • B
    4% (1)
  • C
    4% (1)
  • E
    79% (19)
  • F
    13% (3)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice