filmov
tv
22M. Java Basics for Selenium - Java Arrays - Interview Questions

Показать описание
In this video we will see some interview questions about java arrays.
What is difference between length and length() method in java ?
length : we have length instance variable in arrays which will return the number of values or objects in array. For example : String days[]={” Sun”,”Mon”,”wed”,”thu”,”fri”,”sat”}; Will return 6 since the number of values in days array is 6.
Can you change the size of an array once you created?
No. You can’t change it.
How to access array elements in java?
Using index and index starts from 0.
Where does array stored in memory?
Array is created in heap space of JVM memory. Since array is object in Java, even if you create array locally inside a method or block, object is always allocated memory from heap.
Can you store a string into an array of integer in java?
No. You will get a compile time error.
What is ArrayIndexOutOfBounds Exception?
ArrayIndexOutOfBounds exception comes when your code tries to access an invalid index from a given array.
What is a two dimensional array in java?
It’s an array of array in java. You can declare a two dimensional array with three rows and three columns as
int[][] primes = new int[3][3]
What is ArrayStoreException?
ArrayStoreException comes when you have stored an element of type other than the type of array.
How can you iterate over an array in java?
You can iterate over an array using a for loop or a for each loop.
How to sort elements in an array?
How to search an array to check if an element exists there?
Can we use = to copy an array into another array?
We can’t use = to copy an array to another array. Arrays are mutable and when we use = to copy an array, it won’t really copy the array but the second array points to the same memory area of the first array. Since arrays are mutable, if we change a value in an array it changes the value in second array also.
What is difference between length and length() method in java ?
length : we have length instance variable in arrays which will return the number of values or objects in array. For example : String days[]={” Sun”,”Mon”,”wed”,”thu”,”fri”,”sat”}; Will return 6 since the number of values in days array is 6.
Can you change the size of an array once you created?
No. You can’t change it.
How to access array elements in java?
Using index and index starts from 0.
Where does array stored in memory?
Array is created in heap space of JVM memory. Since array is object in Java, even if you create array locally inside a method or block, object is always allocated memory from heap.
Can you store a string into an array of integer in java?
No. You will get a compile time error.
What is ArrayIndexOutOfBounds Exception?
ArrayIndexOutOfBounds exception comes when your code tries to access an invalid index from a given array.
What is a two dimensional array in java?
It’s an array of array in java. You can declare a two dimensional array with three rows and three columns as
int[][] primes = new int[3][3]
What is ArrayStoreException?
ArrayStoreException comes when you have stored an element of type other than the type of array.
How can you iterate over an array in java?
You can iterate over an array using a for loop or a for each loop.
How to sort elements in an array?
How to search an array to check if an element exists there?
Can we use = to copy an array into another array?
We can’t use = to copy an array to another array. Arrays are mutable and when we use = to copy an array, it won’t really copy the array but the second array points to the same memory area of the first array. Since arrays are mutable, if we change a value in an array it changes the value in second array also.