Explore topic-wise InterviewSolutions in .

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.

1.

Which of these methods can convert an object into a List?(a) SetList()(b) ConvertList()(c) singletonList()(d) CopyList()The question was posed to me in an online interview.Asked question is from Collection Algorithms in section java.util – The Collections Framework of Java

Answer»

The CORRECT OPTION is (c) singletonList()

Explanation: singletonList() returns the object as an immutable LIST. This is an EASY way to convert a single object into a list. This was added by Java 2.0.

2.

Which of these methods can randomize all elements in a list?(a) rand()(b) randomize()(c) shuffle()(d) ambiguous()I got this question by my college professor while I was bunking the class.This intriguing question originated from Collection Algorithms topic in section java.util – The Collections Framework of Java

Answer» RIGHT ANSWER is (c) SHUFFLE()

EASY explanation: shuffle – randomizes all the elements in a list.
3.

Which of these methods sets every element of a List to a specified object?(a) set()(b) fill()(c) Complete()(d) add()I got this question in homework.This intriguing question comes from Collection Algorithms topic in division java.util – The Collections Framework of Java

Answer» RIGHT ANSWER is (B) FILL()

The EXPLANATION is: None.
4.

Which of these is an incorrect form of using method max() to obtain a maximum element?(a) max(Collection c)(b) max(Collection c, Comparator comp)(c) max(Comparator comp)(d) max(List c)This question was addressed to me during an interview.This question is from Collection Algorithms in division java.util – The Collections Framework of Java

Answer»

The correct choice is (c) MAX(Comparator comp)

To explain: Its illegal to call max() only with comparator, we NEED to give the COLLECTION to be searched into.

5.

Which of these is a Basic interface that all other interface inherits?(a) Set(b) Array(c) List(d) CollectionThe question was asked in an interview for job.My question is based upon Collections Interface in section java.util – The Collections Framework of Java

Answer»

The CORRECT option is (d) Collection

For EXPLANATION I would say: Collection interface is inherited by all other interfaces like Set, Array, MAP etc. It DEFINES core methods that all the collections like set, map, arrays etc will have

6.

Which of this interface must contain a unique element?(a) Set(b) List(c) Array(d) CollectionThis question was posed to me in final exam.I'm obligated to ask this question of Collections Interface topic in chapter java.util – The Collections Framework of Java

Answer»

Correct choice is (a) SET

The explanation: Set INTERFACE extends collection interface to handle SETS, which must contain unique elements.

7.

Which of these interface handle sequences?(a) Set(b) List(c) Comparator(d) CollectionThe question was asked during a job interview.This interesting question is from Collections Interface topic in chapter java.util – The Collections Framework of Java

Answer» RIGHT CHOICE is (B) List

To EXPLAIN: NONE.
8.

Which of these interface declares core method that all collections will have?(a) set(b) EventListner(c) Comparator(d) CollectionI got this question in an international level competition.I want to ask this question from Collections Interface in division java.util – The Collections Framework of Java

Answer»

Right answer is (d) Collection

To explain I would say: Collection INTERFACES defines CORE methods that all the COLLECTIONS like set, MAP, arrays etc will have.

9.

Which of these method of Array class is used sort an array or its subset?(a) binarysort()(b) bubblesort()(c) sort()(d) insert()The question was asked in final exam.Question is from Java.util topic in section java.util – The Collections Framework of Java

Answer» RIGHT option is (C) SORT()

Explanation: NONE.
10.

Which of this method is used to make all elements of an equal to specified value?(a) add()(b) fill()(c) all()(d) set()This question was posed to me in an international level competition.My doubt is from Java.util in portion java.util – The Collections Framework of Java

Answer» RIGHT choice is (b) fill()

For EXPLANATION: fill() method assigns a value to all the elements in an array, in other WORDS, it fills the array with SPECIFIED value.
11.

Which of these standard collection classes implements all the standard functions on list data structure?(a) Array(b) LinkedList(c) HashSet(d) AbstractSetThe question was posed to me during an internship interview.The above asked question is from Java.util in division java.util – The Collections Framework of Java

Answer» CORRECT CHOICE is (a) Array

For EXPLANATION: NONE.
12.

If the size of the array used to implement a circular queue is MAX_SIZE. How rear moves to traverse inorder to insert an element in the queue?(a) rear=(rear%1)+MAX_SIZE(b) rear=(rear+1)%MAX_SIZE(c) rear=rear+(1%MAX_SIZE)(d) rear=rear%(MAX_SIZE+1)I got this question during an online exam.I would like to ask this question from Data Structures-Queue topic in section java.util – The Collections Framework of Java

Answer»

The correct choice is (B) rear=(rear+1)%MAX_SIZE

The EXPLANATION is: The FRONT and rear POINTER od circular QUEUE point to the first element.

13.

Where does a new element be inserted in linked list implementation of a queue?(a) Head of list(b) Tail of list(c) At the centre of list(d) All the old entries are pushed and then the new element is insertedThis question was posed to me during an online exam.My doubt is from Data Structures-Queue topic in division java.util – The Collections Framework of Java

Answer»

The correct OPTION is (B) Tail of list

Easy EXPLANATION: To maintain FIFO, newer elements are INSERTED to the tail of the list.

14.

Which data structure is used in Breadth First Traversal of a graph?(a) Stack(b) Queue(c) Array(d) TreeThe question was asked during an online interview.Origin of the question is Data Structures-Queue topic in section java.util – The Collections Framework of Java

Answer» RIGHT choice is (B) Queue

The EXPLANATION: In Breadth First Traversal of graph the NODES at the same level are ACCESSED in the order of retrieval (i.e FIFO).
15.

What is the correct method used to insert and delete items from the queue?(a) push and pop(b) enqueue and dequeue(c) enqueue and peek(d) add and removeThis question was posed to me by my school principal while I was bunking the class.The query is from Data Structures-Queue in section java.util – The Collections Framework of Java

Answer»

Correct choice is (b) ENQUEUE and dequeue

The best explanation: enqueue is pushing item into queue; dequeue is removing item from queue; peek returns object WITHOUT removing it from queue.

Stack uses PUSH and pop METHODS. add and remove are USED in the list.

16.

What are the use of front and rear pointers in CircularQueue implementation?(a) Front pointer points to first element; rear pointer points to the last element(b) Rear pointer points to first element; front pointer points to the last element(c) Front and read pointers point to the first element(d) Front pointer points to the first element; rear pointer points to null objectThe question was asked by my school principal while I was bunking the class.Enquiry is from Data Structures-Queue in portion java.util – The Collections Framework of Java

Answer»

Right answer is (c) Front and READ POINTERS point to the first element

For EXPLANATION: CircularQueue implementation is an abstract CLASS where first and rear POINTER point to the same object.

17.

What is difference between dequeue() and peek() function of java?(a) dequeue() and peek() remove and return the next time in line(b) dequeue() and peek() return the next item in line(c) dequeue() removes and returns the next item in line while peek() returns the next item in line(d) peek() removes and returns the next item in line while dequeue() returns the next item in lineThis question was posed to me in an internship interview.Enquiry is from Data Structures-Queue in section java.util – The Collections Framework of Java

Answer»

Correct answer is (c) dequeue() REMOVES and returns the NEXT item in line while peek() returns the next item in line

Easiest EXPLANATION: dequeue() removes the item next in line. peek() returns the item without removing it from the queue.

18.

What is the difference between Queue and Stack?(a) Stack is LIFO; Queue is FIFO(b) Queue is LIFO; Stack is FIFO(c) Stack and Queue is FIFO(d) Stack and Queue is LIFOThis question was posed to me at a job interview.This interesting question is from Data Structures-Queue topic in chapter java.util – The Collections Framework of Java

Answer»

Right answer is (a) Stack is LIFO; QUEUE is FIFO

To EXPLAIN: Stack is Last in FIRST out (LIFO) and Queue is First in First out(FIFO).

19.

PriorityQueue is thread safe.(a) True(b) FalseThe question was asked during an interview.My question is from Data Structures-Queue in portion java.util – The Collections Framework of Java

Answer» CORRECT choice is (a) True

The best EXPLANATION: PriorityQueue is not synchronized. BlockingPriorityQueue is the THREAD SAFE IMPLEMENTATION.
20.

What is the remaining capacity of BlockingQueue whose intrinsic capacity is not defined?(a) Integer.MAX_VALUE(b) BigDecimal.MAX_VALUE(c) 99999999(d) Integer.INFINITYThis question was addressed to me in an interview for job.The above asked question is from Data Structures-Queue topic in portion java.util – The Collections Framework of Java

Answer»

Correct option is (a) Integer.MAX_VALUE

To elaborate: A BlockingQueue WITHOUT any INTRINSIC capacity CONSTRAINTS always REPORTS a REMAINING capacity of Integer.MAX_VALUE.

21.

Which of the below is not a subinterface of Queue?(a) BlockingQueue(b) BlockingEnque(c) TransferQueue(d) BlockingQueueThe question was asked in an online interview.My doubt is from Data Structures-Queue in division java.util – The Collections Framework of Java

Answer»

The correct answer is (b) BlockingEnque

To explain I WOULD say: BlockingQueue, TransferQueue and BlockingQueue are SUBINTERFACES of QUEUE.

22.

Which of these is a method of ListIterator used toobtain index of previous element?(a) previous()(b) previousIndex()(c) back()(d) goBack()The question was posed to me in homework.Origin of the question is Iterators in section java.util – The Collections Framework of Java

Answer»

The correct choice is (b) previousIndex()

For EXPLANATION I WOULD say: previousIndex() returns index of PREVIOUS ELEMENT. if there is no previous element then -1 is RETURNED.

23.

Which of these iterators can be used only with List?(a) Setiterator(b) ListIterator(c) Literator(d) None of the mentionedThis question was posed to me during an online exam.My doubt stems from Iterators in portion java.util – The Collections Framework of Java

Answer»

The CORRECT CHOICE is (B) ListIterator

For EXPLANATION: NONE.

24.

Which of these methods can be used to move to next element in a collection?(a) next()(b) move()(c) shuffle()(d) hasNext()I got this question in unit test.The query is from Iterators in division java.util – The Collections Framework of Java

Answer»

The CORRECT CHOICE is (a) NEXT()

EASY explanation: None.

25.

Which of these methods is used to obtain an iterator to the start of collection?(a) start()(b) begin()(c) iteratorSet()(d) iterator()The question was asked during an internship interview.This interesting question is from Iterators in division java.util – The Collections Framework of Java

Answer»

Correct answer is (d) ITERATOR()

For explanation I would SAY: To OBTAIN an iterator to the start of the start of the collection we use iterator() METHOD.

26.

Which of these return type of hasNext() method of an iterator?(a) Integer(b) Double(c) Boolean(d) Collections ObjectI had been asked this question in my homework.Enquiry is from Iterators in portion java.util – The Collections Framework of Java

Answer»

Right CHOICE is (C) Boolean

For explanation: hasNext() RETURNS boolean values true or false.

27.

Which of these methods deletes all the elements from invoking collection?(a) clear()(b) reset()(c) delete()(d) refresh()I have been asked this question in an international level competition.I'm obligated to ask this question of Collection Framework Overview in chapter java.util – The Collections Framework of Java

Answer»

The CORRECT choice is (a) clear()

To EXPLAIN I would say: clear() METHOD REMOVES all the elements from invoking collection.

28.

Which of this interface is not a part of Java’s collection framework?(a) List(b) Set(c) SortedMap(d) SortedListThe question was posed to me in an interview.Origin of the question is Collection Framework Overview in division java.util – The Collections Framework of Java

Answer»

Correct option is (d) SORTEDLIST

The EXPLANATION: SortedList is not a PART of COLLECTION FRAMEWORK.

29.

Which of these classes is not part of Java’s collection framework?(a) Maps(b) Array(c) Stack(d) QueueI had been asked this question in an online quiz.Query is from Collection Framework Overview in chapter java.util – The Collections Framework of Java

Answer»

The CORRECT OPTION is (a) MAPS

Easy explanation: Maps is not a PART of collection FRAMEWORK.

30.

Which of these packages contain all the collection classes?(a) java.lang(b) java.util(c) java.net(d) java.awtThis question was posed to me during an interview.My doubt is from Collection Framework Overview topic in portion java.util – The Collections Framework of Java

Answer» CORRECT answer is (B) java.util

To EXPLAIN I would say: None.
31.

Which of these Exceptions is thrown by remote method?(a) RemoteException(b) InputOutputException(c) RemoteAccessException(d) RemoteInputOutputExceptionThe question was asked in final exam.My question comes from Remote Method Invocation (RMI) topic in division java.util – The Collections Framework of Java

Answer»

The CORRECT option is (a) REMOTEEXCEPTION

Best EXPLANATION: All remote methods THROW RemoteException.

32.

Which of these class is used for creating a client for a server-client operations?(a) serverClientjava(b) Client.java(c) AddClient.java(d) ServerClient.javaThe question was asked in exam.My question is based upon Remote Method Invocation (RMI) topic in division java.util – The Collections Framework of Java

Answer» RIGHT CHOICE is (C) AddClient.java

For EXPLANATION: NONE.
33.

Which of these package is used for remote method invocation?(a) java.applet(b) java.rmi(c) java.lang.rmi(d) java.lang.reflectI had been asked this question in my homework.The question is from Remote Method Invocation (RMI) in division java.util – The Collections Framework of Java

Answer» RIGHT ANSWER is (B) java.rmi

The BEST explanation: None.
34.

What is Remote method invocation (RMI)?(a) RMI allows us to invoke a method of java object that executes on another machine(b) RMI allows us to invoke a method of java object that executes on another Thread in multithreaded programming(c) RMI allows us to invoke a method of java object that executes parallely in same machine(d) None of the mentionedThe question was posed to me in an internship interview.I would like to ask this question from Remote Method Invocation (RMI) in division java.util – The Collections Framework of Java

Answer» RIGHT ANSWER is (a) RMI allows us to invoke a method of JAVA object that executes on another MACHINE

Easiest explanation: Remote method invocation RMI allows us to invoke a method of java object that executes on another machine.
35.

Which of these methods are member of Remote class?(a) checkIP()(b) addLocation()(c) AddServer()(d) None of the mentionedI got this question by my school principal while I was bunking the class.This key question is from Remote Method Invocation (RMI) in portion java.util – The Collections Framework of Java

Answer»

Right CHOICE is (d) None of the mentioned

The explanation is: REMOTE class does not define any METHODS, its PURPOSE is simply to indicate that an interface uses remote methods.

36.

Which of these method is used to calculate number of bits required to hold the BitSet object?(a) size()(b) length()(c) indexes()(d) numberofBits()I have been asked this question during an interview for a job.The above asked question is from Java.util topic in chapter java.util – The Collections Framework of Java

Answer»

The correct CHOICE is (b) LENGTH()

The BEST EXPLANATION: None.

37.

Which of these is a method of class Date which is used to search whether object contains a date before the specified date?(a) after()(b) contains()(c) before()(d) compareTo()I had been asked this question during an internship interview.This question is from Java.util topic in division java.util – The Collections Framework of Java

Answer»

Right option is (C) before()

Explanation: before() returns TRUE if the invoking Date object CONTAINS a date that is EARLIER than one specified by date, otherwise it returns FALSE.

38.

Which of these method is used to make a bit zero specified by the index?(a) put()(b) set()(c) remove()(d) clear()The question was posed to me in homework.I want to ask this question from Java.util topic in chapter java.util – The Collections Framework of Java

Answer» CORRECT ANSWER is (d) CLEAR()

For EXPLANATION: NONE.
39.

Which of these methods is used to retrieve the elements in properties object at specific location?(a) get()(b) Elementat()(c) ElementAt()(d) getProperty()I have been asked this question by my college professor while I was bunking the class.Asked question is from Java.util topic in portion java.util – The Collections Framework of Java

Answer» RIGHT answer is (d) GETPROPERTY()

EASIEST EXPLANATION: None.
40.

Which of these class object has an architecture similar to that of array?(a) Bitset(b) Map(c) Hashtable(d) All of the mentionedThe question was posed to me in an interview for internship.I need to ask this question from Java.util in chapter java.util – The Collections Framework of Java

Answer» CORRECT answer is (a) Bitset

For explanation: Bitset CLASS CREATES a SPECIAL type of array that holds bit values. This array can increase in SIZE as needed.
41.

Which of these is a class which uses String as a key to store the value in object?(a) Array(b) ArrayList(c) Dictionary(d) PropertiesThis question was posed to me during an internship interview.The query is from Java.util in portion java.util – The Collections Framework of Java

Answer» RIGHT CHOICE is (d) Properties

The EXPLANATION is: NONE.
42.

Which of these is the interface of legacy is implemented by Hashtable and Dictionary classes?(a) Map(b) Enumeration(c) HashMap(d) HashtableI have been asked this question in an interview.My question comes from Java.util in portion java.util – The Collections Framework of Java

Answer» RIGHT CHOICE is (a) Map

For explanation: Dictionary, Map & HASHTABLE all IMPLEMENT Map interface HENCE all of them uses keys to store value in the object.
43.

Which of these class object uses the key to store value?(a) Dictionary(b) Map(c) Hashtable(d) All of the mentionedThis question was posed to me in an international level competition.I need to ask this question from Java.util in portion java.util – The Collections Framework of Java

Answer»

Right choice is (d) All of the mentioned

To explain I WOULD say: DICTIONARY, Map & HASHTABLE all implement Map interface HENCE all of them uses keys to STORE value in the object.

44.

Which of these method is used to insert value and its key?(a) put()(b) set()(c) insertElement()(d) addElement()I have been asked this question during an interview for a job.I'd like to ask this question from Java.util in portion java.util – The Collections Framework of Java

Answer» CORRECT ANSWER is (a) PUT()

BEST explanation: None.
45.

What is the name of a data member of class Vector which is used to store a number of elements in the vector?(a) length(b) elements(c) elementCount(d) capacityThis question was posed to me during an interview for a job.I want to ask this question from Java.util topic in chapter java.util – The Collections Framework of Java

Answer» RIGHT OPTION is (C) elementCount

Best EXPLANATION: NONE.
46.

Which of these is the interface of legacy?(a) Map(b) Enumeration(c) HashMap(d) HashtableI had been asked this question during a job interview.The above asked question is from Java.util in division java.util – The Collections Framework of Java

Answer» CORRECT OPTION is (B) Enumeration

To EXPLAIN: NONE.
47.

Which of these are legacy classes?(a) Stack(b) Hashtable(c) Vector(d) All of the mentionedI got this question during an online exam.This question is from Java.util in section java.util – The Collections Framework of Java

Answer»

The CORRECT OPTION is (d) All of the mentioned

To explain: Stack, Hashtable, Vector, PROPERTIES and DICTIONARY are legacy classes.

48.

Which of these class object can be used to form a dynamic array?(a) ArrayList(b) Map(c) Vector(d) ArrayList & VectorThis question was posed to me in an interview for job.I'm obligated to ask this question of Java.util in portion java.util – The Collections Framework of Java

Answer»

The correct choice is (d) ArrayList & Vector

Easy explanation: Vectors are dynamic arrays, it contains MANY legacy METHODS that are not part of collection FRAMEWORK, and hence these methods are not present in ArrayList. But both are USED to FORM dynamic arrays.

49.

Which of these methods can be used to obtain set of all keys in a map?(a) getAll()(b) getKeys()(c) keyall()(d) keySet()The question was posed to me in my homework.This intriguing question originated from Java.util in portion java.util – The Collections Framework of Java

Answer»

The CORRECT option is (d) KEYSET()

To explain I would say: keySet() methods is used to get a SET containing all the keys used in a map. This method provides set view of the keys in the INVOKING map.

50.

Which of these method Map class is used to obtain an element in the map having specified key?(a) search()(b) get()(c) set()(d) look()The question was posed to me in homework.Asked question is from Java.util topic in portion java.util – The Collections Framework of Java

Answer»

Correct ANSWER is (b) GET()

Easiest EXPLANATION: NONE.