Java MCQ – Home
Java Basic MCQ
➤ Java Hello World MCQ
➤ Find Java Keywords
➤ Java Identifier Quiz
➤ Java Data Types Quiz
➤ If-Else MCQ in Java-1
➤ If-Else MCQ in Java-2
Object class MCQ
➤ Object Class Quiz
➤ equals() Method Quiz
➤ Hashcode Value Quiz
➤ toString() Method Quiz
➤ Clone() Method Quiz
Multithreading MCQ
➤ Define a Thread-1
➤ Define a Thread-2
➤ Get/set ThreadName
➤ Thread State MCQ
➤ Thread Priority MCQ
➤ Yield(), join() & sleep()
➤ Synchronization MCQ
➤ Interthread Comms
➤ Deadlock, Daemon
Exception Handling
➤ Exception Handling-1
➤ Exception Handling-2
➤ Exception Handling-3
➤ Java try-catch MCQ-1
➤ Java try-catch MCQ-2
➤ Java try-catch MCQ-3
➤ Nested try-catch MCQ
➤ throw Keyword MCQ
➤ finally Block MCQ-1
➤ finally Block MCQ-2
➤ throws Keyword MCQ
Generics MCQ
➤ Java Generics Quiz-1
➤ Java Generics Quiz-2
➤ Java Generics Quiz-3
Collection Framework
➤ Collections Quiz-1
➤ Collections Quiz-2
➤ ArrayList MCQ-1
➤ ArrayList MCQ-2
➤ LinkedList MCQ
➤ Vector Stack MCQ
➤ Java Cursors MCQ
➤ Java TreeSet MCQ
➤ TreeSet & Comparator
Java LinkedList MCQ | In Java, collection framework classes are used to store elements in value or key-value format without size limitation. We have listed some Java LinkedList MCQ and programming questions, answer them. See:- Java Collections Quiz-1
Also see- Java Collection Framework Overview, Java Collection Interface, List Interface in Java
Q1) In Java, the underlying data structure for the LinkedList class is?
a) Singly linked list
b) Doubly linked list
c) Circular linked list
d) None of these
View Answer
Answer:- b) Doubly linked listQ2) What will be the output for the below statements?
List list = new LinkedList();
System.out.println(list instanceof RandomAccess);
a) true
b) false
c) both
d) None of these
View Answer
Answer:- b) falseLinkedList class doesn’t implement RandomAccess interface therefore it gives “false” as output.
Q3) LinkedList class implements?
a) List interface
b) Deque interface
c) Both (a) and (b)
d) None of these
View Answer
Answer:- c) Both (a) and (b)LinkedList class implements both List(I) and Deque(I) interface.
Q4) Find the output of the below LinkedList program?
import java.util.LinkedList;
import java.util.List;
public class Test {
public static void main(String[] args) {
List<Integer> ll = new LinkedList<Integer>();
ll.add(100);
ll.add(220);
ll.add(50);
ll.add(null);
ll.add(100);
ll.add(50);
ll.add(100);
ll.add(null);
System.out.println(ll);
}
}
a) [100, 220, 50, null, 100, 50, 100, null]
b) [100, 220, 50, 100, 50, 100]
c) [100, 220, 50, null]
d) None of these
View Answer
Answer:- a) [100, 220, 50, null, 100, 50, 100, null]LinkedList allows storing the duplicates and null values without any restriction.
Q5) Find the output of the below Java LinkedList program?
import java.util.LinkedList;
public class Test {
public static void main(String[] args) {
LinkedList<Integer> ll = new LinkedList<Integer>();
ll.add(100);
ll.add(220);
ll.add(50);
ll.add(100);
ll.add(50);
ll.addFirst(999);
ll.addLast(888);
System.out.println(ll);
}
}
a) [100, 220, 50, 100, 50]
b) [999, 100, 220, 50, 888]
c) [999, 100, 220, 50, 100, 50, 888]
d) None of these
View Answer
Answer:- a) [999, 100, 220, 50, 100, 50, 888]The addFirst(object) and addLast(object) method add element first and last index respectively.
Q6) Find the output of the below Java LinkedList program?
import java.util.LinkedList;
public class Test {
public static void main(String[] args) {
LinkedList<Integer> ll = new LinkedList<Integer>();
ll.add(100);
ll.add(50);
ll.add(220);
ll.add(100);
ll.add(50);
System.out.println(ll.getFirst()
+ " " + ll.getLast());
}
}
a) 100 50
b) 100 220
c) 50 50
d) None of these
View Answer
Answer:- a) 100 50The getFirst() and getLast() methods fetch the elements at the first and last index in the list and return to the called method.
Q7) Find the output of the below Java LinkedList program?
import java.util.LinkedList;
public class Test {
public static void main(String[] args) {
LinkedList<Integer> ll = new LinkedList<Integer>();
ll.add(100);
ll.add(50);
ll.add(220);
ll.add(100);
ll.add(50);
System.out.println(ll.removeFirst()
+ " " + ll.removeLast()
+ "; " + ll);
}
}
a) true true; [50, 220, 100]
b) true true; [100, 50, 220, 100, 50]
c) 100 50; [50, 220, 100]
d) 100 50; [100, 50, 220, 100, 50]
View Answer
Answer:- c) 100 50; [50, 220, 100]The removeFirst() and removeLast() method removes the first and last element in the list and returns the corresponding elements.
Q8) Which of the following statement is true?
a) In LinkedList elements are stored in consecutive memory locations.
b) In LinkedList elements are not stored in consecutive memory locations.
View Answer
Answer:- b) In LinkedList elements are not stored in consecutive memory locations.In LinkedList, the elements will not be stored in consecutive memory locations and hence retrieval operation becomes complex. Hence it is not recommended to use LinkedList if our primary task is to perform retrieval operation, in that case, ArrayList is the best choice.
If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!