Question discussion

What is the output of the following Java program?import java.util.*; public class Main { public static void main(String[] args) { ArrayList…

901Medium DSSSB TGT Computer Science 0 replies

What is the output of the following Java program?

import java.util.*;
public class Main {
    public static void main(String[] args) {
        ArrayList<Integer> l = new ArrayList<>(Arrays.asList(5, 6, 7, 8));
        l.remove(1);
        l.remove(Integer.valueOf(8));
        System.out.println(l);
    }
}
  • A[5, 7]
  • B[5, 6, 7]
  • C[6, 7]
  • D[5, 7, 8]
Correct answer: A

Explanation

remove(1) deletes the element at index 1 (the value 6) and remove(Integer.valueOf(8)) deletes the value 8, leaving [5, 7].

Discussion 0

Nobody has replied yet. Start the discussion!