Java Quize Questions
Q.1 A Queue implements First-In-First-Out(FIFO) data structrure.Which method removes the first element of a list?
1. queue.remove
2. queue.get
3. queue.poll
4. queue.dequeue
Ans :- queue.poll
Q.2 Collections in Java are an extension of what class?
1.Util
2.Iterable
3.Correct
4.List
5.Interface
Ans:- Iterable
Q.3 What is a characteristic of an ArrayList?
1.It is faster at removing elements from the middle of a list.
2.It takes up less memory than a linked list.
3.It is harder to implement than a linked list.
4.It is slower at retrieving elements at a particular location.
Ans:- It takes up less memory than a linked list.
Q.4 What prints to the console after this code executes?
LinkedList myList = new LinkedList();
myList.add("A");
myList.add("C");
myList.add(2, "B");
myList.remove("B");
System.out.println(myList);
1. [A, C]
2.[C, A]
3.[A]
4.[C]
Ans :- 1. [A, C]
Q.5 You create a HashMap data structure using the following statement. What is the correct way to add a new element?
HashMap datebook = new HashMap<>();
1.datebook.put("Mary", 20210405);
2.datebook.set("Mary", 20210405);
3.datebook.add("Mary", 20210405);
4.datebook.insert("Mary", 20210405);
Ans :- 1.datebook.put("Mary", 20210405);
Q.6 What are you guaranteed when you use a LinkedHashMap as opposed to a HashMap?
1.The order in which the elements were inserted is preserved.
2.The order of the elements is sorted by the datatype.
3.The order is maintained like a stack.
4.The order of the elements is sorted by the frequency in which they are accessed.
Ans:- The order in which the elements were inserted is preserved.
Q.7 You want to create a list that is capable of returning the last element that was accessed. What is the correct declaration statement to accomplish this?
1.LinkedHashMap logbook = new LinkedHashMap(false, 0.75f, 4);
2.LinkedHashMap logbook = new LinkedHashMap(4, 0.75f, false);
3.LinkedHashMap logbook = new LinkedHashMap(4, 0.75f, true);
4.LinkedHashMap logbook = new LinkedHashMap(true, 0.75f, 4);
Ans:- LinkedHashMap logbook = new LinkedHashMap(4, 0.75f, true);
Q.8
Comments
Post a Comment