Core Java Interview Questions – Arrays

This Core Java interview questions post providing all the interview questions about arrays including what is array, how to access array elements, how to copy array elements, how to sort array elements, how to find the length of an array, what is a two-dimensional array and much more.


What is the Static memory?
The static memory means fixed memory.


What is an Array?
Collection of elements store in consecutive memory locations.


Is array static in java?
Arrays are static in memory and Objects in Java.


How to access array elements?
Using array index starting with 0 to length-1.


How to find the length of the array?
Using pre-defined variable “length”.


How to sort Array elements in java?
You can sort an array in Java by using Arrays.sort() method.


How to copy all the elements of Array in java?
Either by iterating manually using the loop or you can use System.arrayCopy() method.


Where does array stored in memory?
The array is created in heap space of JVM memory.
An array variable can be either static, non-static or local.


How to declare array variable in java?
Arrays are objects, hence we can create an array using “new” keyword.


What happens if we access the array element which is out of bounds?
It gives ArrayIndexOutOfBoundsException.


Can we increase or decrease the size of the array?
No, hence array size is static in java.


Can we store heterogeneous elements in Array?
No, array accepts only homogenous elements.


Can we store objects in Array?
Yes, the array can hold both primitive data as well as objects but of same data type.


Can you use Generics in array declaration?
No, you cannot use Generics because the array is already data restricted.


Is it possible to initialize an array directly as int arr[] = {1, 2, 3, 4, 5};
Yes, object memory will be allocated internally using “new” operator only.


What is two-dimensional array?
An array is used to process two dimensional data in java application.
int[][] arr = new int[3][3];


>Core java interview questions – Exception Handling<

Share this