Switch to Dark Mode

Java Array Programs

Here are 10 essential multiple-choice questions on Java Array Programs, covering key concepts.

Last Updated : Mar 26, 2025
Discuss
Comments

Question 1

What will be the output of the following program?

Java
int[] arr = {5, 10, 15, 20, 25};
int sum = 0;
for (int num : arr) {
    sum += num;
}
System.out.println(sum);


  • A

    50

  • B

    60

  • C

    55

  • D

    65

Question 2

How do you find the largest element in an array in Java?

  • A

    Using Collections.max(arr)

  • B

    Iterating and comparing each element

  • C

    Using Math.max(arr)

  • D

    Sorting and taking the first element

Question 3

What will be the output of the following code?

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

    1

  • B

    3

  • C

    4

  • D

    9

Question 4

What is the best way to reverse an array in Java?

  • A

    Using Collections.reverse()

  • B

    Using a loop with swapping

  • C

    Using Arrays.reverse()

  • D

    Using Math.reverse()

Question 5

What will be the output of the following program?

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

    4

  • B

    5

  • C

    6

  • D

    Compilation Error

Question 6

How do you check if two arrays are equal in Java?


  • A

    arr1 == arr2

  • B

    Arrays.equals(arr1, arr2)

  • C

    arr1.equals(arr2)


  • D

    arr1.compare(arr2)

Question 7

What will be the output of the following program?

Java
int[] arr1 = {1, 2, 3};
int[] arr2 = arr1;
arr2[0] = 10;
System.out.println(arr1[0]);


  • A

    1

  • B

    10

  • C

    Compilation Error


  • D

    Runtime Error

Question 8

What is the correct way to copy an array in Java?

  • A

    arr2 = arr1;

  • B

    arr2 = Arrays.copyOf(arr1, arr1.length);

  • C

    arr2.clone(arr1);

  • D

    Arrays.copy(arr1, arr2);

Question 9

How do you find duplicate elements in an array?

  • A

    Using HashSet

  • B

    Using arr.contains()

  • C

    Using arr.duplicates()


  • D

    Java does not support duplicate detection

Question 10

What is the time complexity of linear search in an array?

  • A

    O(1)

  • B

    O(log n)

  • C

    O(n)

  • D

    O(n^2)

There are 10 questions to complete.

Take a part in the ongoing discussion