Java OCA OCP Practice Question 3165

Question

Which statement, when inserted independently at (1), will result in program output that does not include the word shell?.

import static java.lang.System.out;
import java.util.Collections;
import java.util.NavigableSet;
import java.util.TreeSet;
public class Main {
  public static void main(String[] args) {
    NavigableSet<String> strSetA = new TreeSet<String>();
    Collections.addAll(strSetA, "set", "shell", "soap", "swan");
    // (1) INSERT STATEMENT HERE.
  }/*from www  . j  a  v a 2  s  .  c o  m*/
}

Select the two correct answers.

(a)  out.println(strSetA.headSet("soap", true));
(b)  out.println(strSetA.headSet("soap", false));
(c)  out.println(strSetA.tailSet("soap", true));
(d)  out.println(strSetA.tailSet("soap", false));
(e)  out.println(strSetA.subSet("set", false, "soap", true));
(f)  out.println(strSetA.subSet("set", true, "soap", false));


(c)

Note

Note that the methods higher() and lower() are "stricter" than the methods ceiling() and floor().




PreviousNext

Related