Java OCA OCP Practice Question 1101

Question

What is the output of the following?

import java.util.Arrays;
import java.util.List;

public class Main {
   public static void main(String[] args) {
      List<String> v = Arrays.asList("can", "cup");
      for (int c = 0; c < v.size(); c++)
         System.out.print(v.get(c) + ",");

   }//from  www  .  ja v  a  2 s.  co  m
}
  • A. can,cup,
  • B. cup,can,
  • C. The code does not compile.
  • D. None of the above


A.

Note

This is a correct loop to go through an ArrayList or List starting from the beginning.

It starts with index 0 and goes to the last index in the list.

Option A is correct.




PreviousNext

Related