Java Arrays Interview Questions

    Question 1JAVA - Array Declaration

    Which of the following is a valid array declaration in Java?

    Question 2JAVA - Array Initialization

    What will be the default values of an int array in Java?

    Question 3JAVA - Array Length

    What will this code print?

    int arr[] = {10, 20, 30, 40}; System.out.println(arr.length);

    Question 4JAVA - Index Out of Bounds

    What will happen in the code?

    int arr[] = new int[3]; System.out.println(arr[3]);

    Question 5JAVA - Enhanced For Loop

    What will be the output?

    int[] nums = {1, 2, 3}; for(int n : nums) { System.out.print(n + " "); }

    Question 6JAVA - Multi-Dimensional Array

    What will this code print?

    int[][] arr = { {1, 2}, {3, 4} }; System.out.println(arr[1][0]);

    Question 7JAVA - Array Reference

    What will this code print?

    int[] a = {1, 2, 3}; int[] b = a; b[0] = 99; System.out.println(a[0]);

    Question 8JAVA - Array Sorting

    Which class provides a built-in method to sort arrays in Java?

    Question 9JAVA - Array Copy

    Which method is used for copying array elements efficiently?

    Question 10JAVA - Array to String

    What will this code print?

    int[] arr = {1, 2, 3}; System.out.println(arr);