What is the result?

Given the code fragment:

What is the result?
A. Compilation fails.
B. Hi removed
C. An UnsupportedOperationException is thrown at runtime.
D. The program compiles, but it prints nothing.

Download Printable PDF. VALID exam to help you PASS.

3 thoughts on “What is the result?

  1. If syntax errors fixed in arr and arrList declarations, compilation error arises due to not reachable “s” in code block of if statement

    public static void main(String[] args) {
    String[] arr = {“Hi”, “How”, “Are”, “You”};
    List arrList = new ArrayList(Arrays.asList(arr));

    if(arrList.removeIf(s -> { return s.length() <= 2;})){
    System.out.println(s+ " removed");
    };
    }

  2. A:
    Test17.java:3: error: ‘)’ expected
    String [] arr = (“Hi”, “How”, “Are”, “You”);
    ^
    ………..
    Test17.java:5: error: ‘;’ expected
    if (arrList.removeIf((string s) -> (return s.length() <=2 ))) {
    ^
    Test17.java:9: error: class, interface, or enum expected
    }
    ^
    14 errors

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.