Java Arrays

Last Updated :
Discuss
Comments

Question 1

Which of the following is the correct way to declare an array in Java?


  • A

    int arr[5];

  • B

    int arr = new int(5);

  • C

    int[] arr = new int[5];

  • D

    array<int> arr = new int[5];

Question 2

What will be the output of the following code?

Java
int[] arr = {1, 2, 3, 4, 5};
System.out.println(arr[2]);
  • A

    1

  • B

    2

  • C

    3

  • D

    4

Question 3

What is the default value of an integer array in Java?


  • A

    null

  • B

    0

  • C

    garbage value


  • D

    depends on JVM

Question 4

Which of the following is used to determine the length of an array in Java?

  • A

    arr.length();

  • B

    arr.size;

  • C

    arr.length;

  • D

    arr.count();

Question 5

What is the time complexity for accessing an element in an array by index?

  • A

    O(1)

  • B

    O(n)

  • C

    O(log n)

  • D

    O(n^2)

Question 6

Which of the following creates an array of 5 integers?

  • A

    int arr[] = new int[5];

  • B

    int arr[5];

  • C

    int arr() = 5;

  • D

    int[5] arr;


Question 7

How do you access the third element of an array arr?


  • A

    arr(3)

  • B

    arr[3]

  • C

    arr[2]

  • D

    arr{3}

Question 8

How many rows and columns are in a 2D array int[][] arr = new int[3][4];?


  • A

    3 rows, 4 columns

  • B

    4 rows, 3 columns


  • C

    3 elements

  • D

    7 elements

Question 9

Which of these best defines a multidimensional array in Java?


  • A

    int arr[][]


  • B

    int[] arr[]


  • C

    Both a and b

  • D

    int arr(2)(3)

There are 9 questions to complete.

Take a part in the ongoing discussion