InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 51. |
Which of these method is used to remove all keys/values pair from the invoking map?(a) delete()(b) remove()(c) clear()(d) removeAll()The question was asked in unit test.This interesting question is from Java.util in portion java.util – The Collections Framework of Java |
| Answer» | |
| 52. |
Which of these classes provide implementation of map interface?(a) ArrayList(b) HashMap(c) LinkedList(d) DynamicListThe question was asked in a national level competition.This intriguing question comes from Java.util in chapter java.util – The Collections Framework of Java |
|
Answer» Correct ANSWER is (B) HashMap |
|
| 53. |
Which of this method is used to change an element in a LinkedList Object?(a) change()(b) set()(c) redo()(d) add()This question was posed to me in an internship interview.This intriguing question comes from Java.util in portion java.util – The Collections Framework of Java |
|
Answer» The CORRECT answer is (b) set() |
|
| 54. |
Which of these object stores association between keys and values?(a) Hash table(b) Map(c) Array(d) StringThe question was posed to me by my college director while I was bunking the class.I need to ask this question from Java.util in section java.util – The Collections Framework of Java |
|
Answer» CORRECT CHOICE is (B) Map Best EXPLANATION: NONE. |
|
| 55. |
Which of these methods can be used to delete the last element in a LinkedList object?(a) remove()(b) delete()(c) removeLast()(d) deleteLast()The question was posed to me in final exam.Enquiry is from Java.util in division java.util – The Collections Framework of Java |
|
Answer» CORRECT answer is (c) removeLast() For explanation I would SAY: removeLast() and removeFirst() methods are used to remove elements in END and beginning of a linked LIST. |
|
| 56. |
Which of these method of HashSet class is used to add elements to its object?(a) add()(b) Add()(c) addFirst()(d) insert()This question was addressed to me at a job interview.The origin of the question is Java.util in chapter java.util – The Collections Framework of Java |
|
Answer» The CORRECT OPTION is (a) ADD() |
|
| 57. |
Which of these classes implements Set interface?(a) ArrayList(b) HashSet(c) LinkedList(d) DynamicListI had been asked this question in an online quiz.Query is from Java.util in section java.util – The Collections Framework of Java |
|
Answer» Correct option is (b) HashSet |
|
| 58. |
Which of these method is used to add an element to the start of a LinkedList object?(a) add()(b) first()(c) AddFirst()(d) addFirst()I had been asked this question during an interview for a job.Enquiry is from Java.util topic in chapter java.util – The Collections Framework of Java |
| Answer» | |
| 59. |
Which of these standard collection classes implements a linked list data structure?(a) AbstractList(b) LinkedList(c) HashSet(d) AbstractSetThis question was posed to me during an interview.The question is from Java.util topic in portion java.util – The Collections Framework of Java |
|
Answer» CORRECT CHOICE is (B) LinkedList Best EXPLANATION: NONE. |
|
| 60. |
What is the difference between TreeSet and SortedSet?(a) TreeSet is more efficient than SortedSet(b) SortedSet is more efficient than TreeSet(c) TreeSet is an interface; SortedSet is a concrete class(d) SortedSet is an interface; TreeSet is a concrete classThe question was posed to me in semester exam.The question is from Data Structures-Set in section java.util – The Collections Framework of Java |
|
Answer» The correct answer is (d) SortedSet is an INTERFACE; TREESET is a concrete class |
|
| 61. |
What happens if two threads simultaneously modify TreeSet?(a) ConcurrentModificationException is thrown(b) Both threads can perform action successfully(c) FailFastException is thrown(d) IteratorModificationException is thrownThe question was posed to me in homework.Query is from Data Structures-Set in portion java.util – The Collections Framework of Java |
|
Answer» Correct choice is (a) ConcurrentModificationException is thrown |
|
| 62. |
Set has contains(Object o) method.(a) True(b) FalseThe question was posed to me by my school principal while I was bunking the class.My question comes from Data Structures-Set in portion java.util – The Collections Framework of Java |
|
Answer» Correct choice is (a) True |
|
| 63. |
What are the initial capacity and load factor of HashSet?(a) 10, 1.0(b) 32, 0.75(c) 16, 0.75(d) 32, 1.0The question was asked in exam.This interesting question is from Data Structures-Set topic in section java.util – The Collections Framework of Java |
|
Answer» Right answer is (C) 16, 0.75 |
|
| 64. |
What does Collections.emptySet() return?(a) Immutable Set(b) Mutable Set(c) The type of Set depends on the parameter passed to the emptySet() method(d) Null objectThe question was asked in class test.My question is from Data Structures-Set in portion java.util – The Collections Framework of Java |
|
Answer» Correct option is (a) Immutable Set |
|
| 65. |
Do we have get(Object o) method in HashSet.(a) True(b) FalseThe question was posed to me by my school teacher while I was bunking the class.Query is from Data Structures-Set in portion java.util – The Collections Framework of Java |
|
Answer» Correct CHOICE is (b) False |
|
| 66. |
What is the default clone of HashSet?(a) Deep clone(b) Shallow clone(c) Plain clone(d) Hollow cloneI have been asked this question in an international level competition.The question is from Data Structures-Set topic in division java.util – The Collections Framework of Java |
|
Answer» The CORRECT OPTION is (b) Shallow clone |
|
| 67. |
What is the worst case complexity of accessing an element in ArrayList?(a) O(n)(b) O(1)(c) O(nlogn)(d) O(2)This question was posed to me in a job interview.This interesting question is from Data Structures-List in section java.util – The Collections Framework of Java |
|
Answer» RIGHT option is (b) O(1) To explain I would SAY: ARRAYLIST has O(1) complexity for accessing an ELEMENT in ArrayList. O(N) is the complexity for accessing an element from LinkedList. |
|
| 68. |
Which of the below is not an implementation of List interface?(a) RoleUnresolvedList(b) Stack(c) AttibuteList(d) SessionListI have been asked this question during an interview.This intriguing question originated from Data Structures-List topic in portion java.util – The Collections Framework of Java |
|
Answer» The correct answer is (d) SESSIONLIST |
|
| 69. |
Which class provides thread safe implementation of List?(a) ArrayList(b) CopyOnWriteArrayList(c) HashList(d) ListThis question was posed to me in an international level competition.I'm obligated to ask this question of Data Structures-List topic in section java.util – The Collections Framework of Java |
|
Answer» Correct CHOICE is (b) COPYONWRITEARRAYLIST |
|
| 70. |
What is the difference between length() and size() of ArrayList?(a) length() and size() return the same value(b) length() is not defined in ArrayList(c) size() is not defined in ArrayList(d) length() returns the capacity of ArrayList and size() returns the actual number of elements stored in the listThe question was posed to me in an interview.The query is from Data Structures-List in section java.util – The Collections Framework of Java |
|
Answer» Correct answer is (d) length() returns the capacity of ArrayList and size() returns the actual NUMBER of elements stored in the LIST |
|
| 71. |
When two threads access the same ArrayList object what is the outcome of the program?(a) Both are able to access the object(b) ConcurrentModificationException is thrown(c) One thread is able to access the object and second thread gets Null Pointer exception(d) One thread is able to access the object and second thread will wait till control is passed to the second oneThis question was addressed to me during a job interview.I need to ask this question from Data Structures-List in chapter java.util – The Collections Framework of Java |
|
Answer» Right choice is (B) ConcurrentModificationException is thrown |
|
| 72. |
How is Arrays.asList() different than the standard way of initialising List?(a) Both are same(b) Arrays.asList() throws compilation error(c) Arrays.asList() returns a fixed length list and doesn’t allow to add or remove elements(d) We cannot access the list returned using Arrays.asList()The question was asked in an interview for job.My question is taken from Data Structures-List in division java.util – The Collections Framework of Java |
|
Answer» The correct answer is (C) Arrays.asList() returns a FIXED length list and doesn’t allow to add or remove elements |
|
| 73. |
How to sort elements of ArrayList?(a) Collection.sort(listObj);(b) Collections.sort(listObj);(c) listObj.sort();(d) Sorter.sortAsc(listObj);This question was addressed to me in an international level competition.My query is from Data Structures-List in chapter java.util – The Collections Framework of Java |
|
Answer» Right choice is (b) COLLECTIONS.sort(listObj); |
|
| 74. |
How to remove duplicates from List?(a) HashSet listToSet = new HashSet(duplicateList);(b) HashSet listToSet = duplicateList.toSet();(c) HashSet listToSet = Collections.convertToSet(duplicateList);(d) HashSet listToSet = duplicateList.getSet();The question was asked in an international level competition.This is a very interesting question from Data Structures-List in portion java.util – The Collections Framework of Java |
|
Answer» Correct OPTION is (a) HASHSET |
|
| 75. |
How can we remove an object from ArrayList?(a) remove() method(b) using Iterator(c) remove() method and using Iterator(d) delete() methodThis question was addressed to me in homework.This intriguing question comes from Data Structures-List topic in portion java.util – The Collections Framework of Java |
|
Answer» The CORRECT option is (c) remove() method and using Iterator |
|
| 76. |
If two threads access the same hashmap at the same time, what would happen?(a) ConcurrentModificationException(b) NullPointerException(c) ClassNotFoundException(d) RuntimeExceptionI had been asked this question in an online interview.Asked question is from Data Structures-HashMap topic in portion java.util – The Collections Framework of Java |
|
Answer» Right OPTION is (a) ConcurrentModificationException |
|
| 77. |
Is hashmap an ordered collection.(a) True(b) FalseI had been asked this question during an interview.Origin of the question is Data Structures-HashMap topic in chapter java.util – The Collections Framework of Java |
|
Answer» Right choice is (b) False |
|
| 78. |
While finding the correct location for saving key value pair, how many times the key is hashed?(a) 1(b) 2(c) 3(d) unlimited till bucket is foundI have been asked this question during an interview for a job.This interesting question is from Data Structures-HashMap in chapter java.util – The Collections Framework of Java |
|
Answer» The CORRECT choice is (B) 2 |
|
| 79. |
What happens if we put a key object in a HashMap which exists?(a) The new object replaces the older object(b) The new object is discarded(c) The old object is removed from the map(d) It throws an exception as the key already exists in the mapThe question was asked during a job interview.This intriguing question originated from Data Structures-HashMap in section java.util – The Collections Framework of Java |
|
Answer» Correct answer is (a) The new object replaces the older object |
|
| 80. |
What is the premise of equality for IdentityHashMap?(a) Reference equality(b) Name equality(c) Hashcode equality(d) Length equalityThe question was posed to me in an online interview.My question comes from Data Structures-HashMap in portion java.util – The Collections Framework of Java |
|
Answer» Right option is (a) Reference equality |
|
| 81. |
Which of the below does not implement Map interface?(a) HashMap(b) Hashtable(c) EnumMap(d) VectorI got this question in quiz.I'd like to ask this question from Data Structures-HashMap in division java.util – The Collections Framework of Java |
|
Answer» Right answer is (d) VECTOR |
|
| 82. |
Which of these methods can be used to obtain a static array from an ArrayList object?(a) Array()(b) covertArray()(c) toArray()(d) covertoArray()The question was posed to me during a job interview.I need to ask this question from Java.util in portion java.util – The Collections Framework of Java |
|
Answer» Correct answer is (C) toArray() |
|
| 83. |
Map implements collection interface?(a) True(b) FalseI have been asked this question in an international level competition.Enquiry is from Data Structures-HashMap topic in section java.util – The Collections Framework of Java |
|
Answer» The correct answer is (B) False |
|
| 84. |
Which of these method of ArrayList class is used to obtain present size of an object?(a) size()(b) length()(c) index()(d) capacity()I had been asked this question by my college professor while I was bunking the class.This question is from Java.util in portion java.util – The Collections Framework of Java |
|
Answer» CORRECT CHOICE is (a) SIZE() To ELABORATE: NONE. |
|
| 85. |
Which of these method can be used to increase the capacity of ArrayList object manually?(a) Capacity()(b) increaseCapacity()(c) increasecapacity()(d) ensureCapacity()I have been asked this question during an interview.This intriguing question originated from Java.util in division java.util – The Collections Framework of Java |
|
Answer» Right option is (d) ensureCapacity() |
|
| 86. |
Which of these class can generate an array which can increase and decrease in size automatically?(a) ArrayList()(b) DynamicList()(c) LinkedList()(d) MallocList()The question was posed to me in a national level competition.This is a very interesting question from Java.util topic in division java.util – The Collections Framework of Java |
|
Answer» The CORRECT CHOICE is (a) ARRAYLIST() |
|
| 87. |
Which of these standard collection classes implements a dynamic array?(a) AbstractList(b) LinkedList(c) ArrayList(d) AbstractSetI got this question during an interview for a job.My enquiry is from Java.util in division java.util – The Collections Framework of Java |
|
Answer» CORRECT answer is (c) ArrayList Explanation: ArrayList class IMPLEMENTS a dynamic array by EXTENDING ABSTRACTLIST class. |
|