Interview Questions and Answers - Order By Newest 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 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 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 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 arraysAns. 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  arraysAns. 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 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 Q61. Is this code valid
String[] strArray = new String[2];
strArray.length = 5; Core Java
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 Q62. What is the problem with this code
String[] strArray = new String[2];
strArray[0] = 5; Core Java
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 Q63. Will this give compile time error ?
Object[] strArray = new String[2];
strArray[0] = 5; Core Java
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 Q64. Write a Program to Find the maximum sum of the sub array ? Data Structure
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 Q65. Difference between List and ArrayList ? Core Java
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 Q66. difference between ArrayList and array ? Core Java
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 Q67. Difference between ArrayList and HashSet ? Core Java
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 Q68. Write a program to make an array act as a set. Core Java
Ans. public Set convertArrayToList(T array[]) {
Set set = new HashSet<>(Arrays.asList(array));
return set;
} 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 Q69. How can we create an arraylist of unique values ? Core Java
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 Q70. What will be the output of exceuting main method ?
public static void main(String[] args){
List list = new ArrayList();
list.add(1);
list.add(2);
list.add(3);
System.out.println(list);
} Core Java
a. 1,2,3 b. Order cannot be determined c. compilation error d. 3,2,1Ans.a. 1,2,3