Java OCA OCP Practice Question 712

Question

What is the output of the following?

20:  List<Character> chars = new ArrayList<>(); 
21:  chars.add('a'); 
22:  chars.add('b'); 
23:  chars.set(1, 'c'); 
24:  chars.remove(0); 
25:  System.out.print(chars.length()); 
  • A. 0
  • B. 1
  • C. 2
  • D. None of the above


D.

Note

Line 25 does not compile.

On an ArrayList, the method to get the number of elements is size.

The length() method is used for a String or StringBuilder.




PreviousNext

Related