Interview Questions and Answers - Order By Newest 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