Core Java - Interview Questions and Answers for 'Array' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Interview Questions and Answers - Order By Newest

   next 30
 Q31. why aren't arrays better than array list ?Core Java
Ans. 1. Arrays don't provide any built in support for sorting searching like operation and we need to do it explicitly.

2. It can hold only homogeneous objects,

3. We have to reserve memory as no dynamic expansion allowed.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arrays  arraylist  arrays vs arraylist     Asked in 3 Companies


 Q32. Why iterators of an array list are fail fast ?Core Java
Ans. Because it's access isn't synchronized and hence access / modification by multiple threads may lead to inconsistent state.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     fail fast  arraylist  collections


 Q33. What problem we could have with ArrayList which aren't possible with Vectors ?Core Java
Ans. ArrayLists aren't synchronized and hence doesn't allow synchronized access. As multiple threads can access an arraylist in parallel, it may result in an inconsistent state.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     vector  arraylist  list  collections      Basic


 Q34. What is the quickest way to find count of duplicate elements in an arraylist, without using iteration or loops ?Core Java
Ans. We can copy the elements to a Set and then find the difference of count between ArrayList and Set. As Set don't allow duplicates , they will be removed in the set.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     collections  arraylist  set


 Q35. Why do we pass an array of strings to main method ?Core Java
Ans. Array of strings in the main method are the list of arguments or parameters which are sent to the application / program.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     main method   main method string array argument


 Q36. What does the following initialization mean ?

ArrayList<LinkedList> traversalPaths = new ArrayList<LinkedList>();

What could be the use of such a collection.
Core Java
Ans. Initialize an ArrayList that will hold LinkedLists i.e every element of the arraylist will be a linked list.

Such collection could be used in algorithms that require first random access and then sequential traversal. For example - Storing traversal paths for a graph wherein we can start from any vertex. Implementing dictionary with each arraylist element holding staring with character and then linked list holding duplicate words.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     collections  linkedlist  arraylist


 Q37. What will the following code print ?

int x[] = new int[5];
x[0] = 1;
x[1] = 2;
      
for(int count=0;count<x.length;count++){
System.out.println(x[count]);
}
Core Java
Ans. 1
2
0
0
0

As arrays are not dynamically expanded , we have declared the array for size 10. As we have only initialized only 2 values , it will print rest as their default values.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arrays


 Q38. What will the following code print

int x[] = new int[5];
x[0] = 1;
x[1] = 2;
      
for(int count=0;count<=x.length;count++){
System.out.println(x[count]);
}
Core Java
Ans. 1
2
0
0
0
ArrayIndexOutOfBoundException: 5

As array index starts with 0 and ends with the index of (size - 1), the index 5 is inaccessible for the array and hence will throw the exception.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arrays


 Q39. How can we convert String into Char array and vice versa ?Core Java
Ans. There is a method toCharArray() within String class that can be used to convert string to char array.

string.toCharArray();

String class has an argument constructor that takes a char array and create a string

new String(charArray);

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     string  char array


 Q40. How can we convert a character or a character array into a String ?Core Java
Ans. String has an argument constructor that take char array as argument and creates a string.

There is no constructor available with String that takes in a character and creates a String. We can use StringBuilder which has a char argument constructor.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     character  char  char array  String  char to String  char array to String


 Q41. Which of the two - Arrays or LinkedList - is a better data structure for implementing Queue ? and Why ?Data Structure
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Arraylist  linkedlist  queue  collections


 Q42. Write an efficient program for printing k largest elements in an array. Elements in array can be in any order.Data Structure
 This question was recently asked at 'Amazon'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arrays  coding  code     Asked in 1 Companies


 Q43. Which of the following - arrays or LinkedList allow elements to be accessed using index and how ? Data Structure
Ans. Arrays allows elements to be accessed directly using the index.

As Array elements are stored in continuous memory locations it's very easy to find the memory address of any element using the formula as following

Memory Address of Array start or index 0 + ( Size of array element * Index )

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arrays  linkedlist


  Q44. Find Intersection/union between two arrays.Core Java
 This question was recently asked at 'Bristlecone,Amazon Lab126,Amazon,Microsoft,Facebook,NCR,Google'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arrays  code  coding     Asked in 7 Companies        frequent


  Q45. Write code to sort an array.Algorithm
Ans. https://www.geeksforgeeks.org/arrays-sort-in-java-with-examples/

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     array  sorting     Asked in 16 Companies      basic        frequent


 Q46. How arrays work internally ?Core Java
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arrays


 Q47. Can we change the size of array once created ?Core Java
Ans. No. Arrays cannot resize dynamically.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     array  array size      Basic


 Q48. What is ArrayStoreException ?Core Java
Ans. It's an exception that is thrown when we attempt to add value of an incompatible type to an array.

For example -

Object[] strArray = new String[2];
strArray[0] = 5;

In this code, strArray reference of type Object has currently been assigned the String array but at line 2 we are trying to add an integer value.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arrays   ArrayStoreException


 Q49. What is an anonymous array in Java ?Core Java
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     anonymous arrays


 Q50. What are jagged arrays ?Core Java
Ans. an array of different sizes

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arrays  jagged arrays


 Q51. Are Arrays treated like primitives or like objects in Java ?Core Java
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arrays


 Q52. How can we check equality for Arrays in Java ?Core Java
Ans. You call the method java.util.Arrays.equals(Object[] a, Object[] a2)?

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arrays


 Q53. Are arrays Thread Safe ?Core Java
Ans. Yes

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arrays  concurrency     Asked in 1 Companies


 Q54. What is the time and space complexity for different operations for arrays ?Core Java
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arrays


 Q55. Difference between Arrays and LinkedList ?Data Structure
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arrays vs linkedlist


 Q56. Can we have 3 dimensional arrays in Java ?Core Java
Ans. Yes

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arrays


 Q57. Can we make array volatile in Java ?Core Java
Ans. Yes, you can make an array (both primitive and reference type array e.g. an int array and String array) volatile in Java but only changes to reference pointing to an array will be visible to all threads, not the whole array

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arrays  volatile


 Q58. Is this array declaration correct ? If not , Why ?

String[] strArray = new String[];
Core Java
Ans. No, We haven't specified the size of array to be initialized.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arrays  array initialization


 Q59. Is this array initialization correct ? If Yes, What will be the size of array ?

String[] strArray = new String[]{"Buggy","Bread"};
Core Java
Ans. Yes, size of the array will be 2.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arrays  array initialization


 Q60. Is this array initialization correct ? If Yes, What will be the size of array ?

String[] strArray = new String[3]{"Buggy","Bread"};
Core Java
Ans. No. It will result in error saying "Cannot define dimension expressions when an array initializer is provided"

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     arrays  array initialization


previous 30   next 30

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: