

MCQOPTIONS
Saved Bookmarks
This section includes 11 Mcqs, each offering curated multiple-choice questions to sharpen your Java knowledge and support exam preparation. Choose a topic below to get started.
1. |
When an array is passed to a method, will the content of the array undergo changes with the actions carried within the function? |
A. | True |
B. | False |
Answer» B. False | |
2. |
What is the worst case complexity of accessing an element in ArrayList? |
A. | O(n) |
B. | O(1) |
C. | O(nlogn) |
D. | O(2) |
Answer» C. O(nlogn) | |
3. |
Which of the below is not an implementation of List interface? |
A. | RoleUnresolvedList |
B. | Stack |
C. | AttibuteList |
D. | SessionList |
Answer» E. | |
4. |
Which class provides thread safe implementation of List? |
A. | ArrayList |
B. | CopyOnWriteArrayList |
C. | HashList |
D. | List |
Answer» C. HashList | |
5. |
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 list |
Answer» E. | |
6. |
How to remove duplicates from List? |
A. | HashSet<String> listToSet = new HashSet<String>(duplicateList); |
B. | HashSet<String> listToSet = duplicateList.toSet(); |
C. | HashSet<String> listToSet = Collections.convertToSet(duplicateList); |
D. | HashSet<String> listToSet = duplicateList.getSet(); |
Answer» B. HashSet<String> listToSet = duplicateList.toSet(); | |
7. |
How can we remove an object from ArrayList? |
A. | remove() method |
B. | using Iterator |
C. | remove() method and using Iterator |
D. | delete() method |
Answer» D. delete() method | |
8. |
WHEN_AN_ARRAY_IS_PASSED_TO_A_METHOD,_WILL_THE_CONTENT_OF_THE_ARRAY_UNDERGO_CHANGES_WITH_THE_ACTIONS_CARRIED_WITHIN_THE_FUNCTION??$ |
A. | True |
B. | False |
Answer» B. False | |
9. |
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() |
Answer» D. We cannot access the list returned using Arrays.asList() | |
10. |
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 one |
Answer» C. One thread is able to access the object and second thread gets Null Pointer exception | |
11. |
How to sort elements of ArrayList? |
A. | Collection.sort(listObj); |
B. | Collections.sort(listObj); |
C. | listObj.sort(); |
D. | Sorter.sortAsc(listObj); |
Answer» C. listObj.sort(); | |