Core Java - Interview Questions and Answers for 'Array' | Search Java 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

   



Core Java - Interview Questions and Answers for 'Array' - 71 question(s) found - Order By Rating

next 30
 Q1. How can we create an arraylist of unique values ?Core Java2020-01-17 09:28:36

Ans. We can put the value in a set to enforce uniqueness and then dum those value into an arraylist.

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

   Like         Discuss         Correct / Improve     arraylist  design  collections


 Q2. Write a program to make an array act as a set.Core Java2020-01-10 15:48:48

 This question was recently asked at 'CVS Healthcare'.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  collections set     Asked in 1 Companies


 Q3. Difference between ArrayList and HashSet ?Core Java2019-02-06 11:24:19

Ans. ArrayList is a list , i.e an implementation of List interface whereas HashSet is a Set and an implementation of Set interface.

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

   Like         Discuss         Correct / Improve     arraylist  hashset


 Q4. difference between ArrayList and array ?Core Java2019-02-06 11:23:55

Ans. ArrayList is a variable length collection class whereas arrays are fixed length primitive structure.

We can use generics with arraylist but not with arrays.

We can store primitive data types within arrays but can't with ArrayList. In ArrayList that needs to be converted to Wrapper objects.


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

   Like         Discuss         Correct / Improve     arraylist  arrays  collection classes  collections      basic        frequent


 Q5. Difference between List and ArrayList ?Core Java2019-01-17 20:28:50

Ans. List is an interface whereas ArrayList is an implementation of List.

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

   Like         Discuss         Correct / Improve     list  arraylist  list vs arraylist  difference between  collections     Asked in 2 Companies      basic


 Q6. Write a Program to Find the maximum sum of the sub array ?Data Structure2018-09-16 16:26:46

 This question was recently asked at 'Reddit'.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     Maximum subarray variant  arrays  sub array  subarray     Asked in 1 Companies


 Q7. Why doesn't this code give compile time error when we are clearly trying to add an integer element to an array of Strings

Object[] strArray = new String[2];
strArray[0] = 5;
Core Java2018-07-25 08:18:37

Ans. Because the reference is of Object Array and the resolution of what it holds is identified at the runtime.

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

would have given the compile time array as the reference is of String array.

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

   Like         Discuss         Correct / Improve     arrays


 Q8. Will this give compile time error ?

Object[] strArray = new String[2];
strArray[0] = 5;
Core Java2018-07-25 08:17:03

Ans. No. But It will throw ArrayStoreException at runtime.

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

   Like         Discuss         Correct / Improve     ArrayStoreException  arrays


 Q9. What is the problem with this code

String[] strArray = new String[2];
strArray[0] = 5;
Core Java2018-07-25 08:16:18

Ans. We are trying to add an integer element to an array of String. Will give compile time error.

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

   Like         Discuss         Correct / Improve     arrays


 Q10. If arrays cannot be resized , Why is this code valid

String[] strArray = new String[2];
strArray = new String[5];
Core Java2018-07-25 08:01:42

Ans. We are not resizing the first array here but assigning the reference strArray to a new Array with size 5.

So after line 2, We have 2 arrays in memory, one with size 2 and other with size 5 with strArray referring to second array with size 5.

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

   Like         Discuss         Correct / Improve     arrays  array initialization


 Q11. Is this code valid

String[] strArray = new String[2];
strArray.length = 5;
Core Java2018-07-25 08:00:02

Ans. It will give compile time error saying "The final field array.length cannot be assigned"

Arrays once initialized cannot be resized.

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

   Like         Discuss         Correct / Improve     arrays  array initialization


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

String[] strArray = new String[3]{"Buggy","Bread"};
Core Java2018-07-25 07:55:04

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


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

String[] strArray = new String[]{"Buggy","Bread"};
Core Java2018-07-25 07:54:15

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


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

String[] strArray = new String[];
Core Java2018-07-25 07:52:50

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


 Q15. Can we make array volatile in Java ?Core Java2018-07-22 07:38:11

 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  volatile


 Q16. Can we have 3 dimensional arrays in Java ?Core Java2018-07-22 07:37:54

Ans. Yes

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

   Like         Discuss         Correct / Improve     arrays


 Q17. Can we declare an array without assigning the size of an array? Core Java2018-07-22 07:36:26

Ans. No, It will throw compile time error saying "must provide either dimension expressions or an array initializer"

Alternatively we can provide array initializer like

String[] strArray = new String[]{"Buggy","Bread"};

which will initialize it to size 2 with values as "Buggy" and "Bread"


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

   Like         Discuss         Correct / Improve     arrays  array initialization


 Q18. Difference between Arrays and LinkedList ?Data Structure2018-07-22 07:24:14

 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


  Q19. Difference between Arrays and ArrayList ?Core Java2018-07-22 07:23:59

Ans. Both Arrays and ArrayLists are used to store elements. Elements can be either primitives or objects in case of Arrays, but only objects can be stored in Arraylist. Array is a fixed length data structure while arraylist is variable length collection class. Once created, you cannot change the size of the arrays, but arraylists can dynamically resize itself when needed.Another notable difference between Arrays and Arrayslist is that arary is part of core java programming and array list is part of collection classes

  Sample Code for arrays arraylist

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

   Like         Discuss         Correct / Improve     array  arraylist  array vs arraylist     Asked in 7 Companies      basic        frequent


 Q20. What is the time and space complexity for different operations for arrays ?Core Java2018-07-22 07:22:09

 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


 Q21. Are arrays Thread Safe ?Core Java2018-07-22 07:21:29

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


 Q22. How can we check equality for Arrays in Java ?Core Java2018-07-22 07:21:05

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


 Q23. Are Arrays treated like primitives or like objects in Java ?Core Java2018-07-22 07:20:34

 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


 Q24. What are jagged arrays ?Core Java2018-07-22 07:19:45

 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  jagged arrays


 Q25. What is an anonymous array in Java ?Core Java2018-07-22 07:18:37

 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


 Q26. What is ArrayStoreException ?Core Java2018-07-22 07:18:05

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


 Q27. Can we change the size of array once created ?Core Java2018-07-22 07:16:31

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


 Q28. How arrays work internally ?Core Java2018-07-22 07:15:43

 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


  Q29. Write code to sort an array.Algorithm2018-07-04 16:15:16

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


  Q30. Find Intersection/union between two arrays.Core Java2018-05-13 19:40:34

 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


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: