- Which of the following is true about Java Collections Framework?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.util.*; 2 public class Test { 3 public static void main(String[] args) { 4 List<String> list = new ArrayList<>(); 5 list.add("Eduinq"); 6 list.add("Portal"); 7 System.out.println(list.get(0)); 8 } 9 } View Answer
Correct answer: A — Eduinq
- Which of the following is true about ArrayList?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 Set<String> set = new HashSet<>(); 2 set.add("Eduinq"); 3 set.add("Eduinq"); 4 System.out.println(set.size()); View Answer
Correct answer: A — 1
- Which of the following is true about HashSet?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 Map<Integer,String> map = new HashMap<>(); 2 map.put(1,"Eduinq"); 3 map.put(2,"Portal"); 4 System.out.println(map.get(2)); View Answer
Correct answer: B — Portal
- Which of the following is true about HashMap?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 Queue<String> q = new LinkedList<>(); 2 q.add("Eduinq"); 3 q.add("Portal"); 4 System.out.println(q.poll()); View Answer
Correct answer: A — Eduinq
- Which of the following is true about PriorityQueue?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 Deque<String> dq = new ArrayDeque<>(); 2 dq.add("Eduinq"); 3 dq.addFirst("Portal"); 4 System.out.println(dq.peek()); View Answer
Correct answer: B — Portal
- Which of the following is true about Iterator?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 List<String> list = new ArrayList<>(); 2 list.add("Eduinq"); 3 Iterator<String> it = list.iterator(); 4 while(it.hasNext()) { 5 System.out.println(it.next()); 6 } View Answer
Correct answer: A — Eduinq
- Which of the following is true about ListIterator?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 List<String> list = new ArrayList<>(); 2 list.add("Eduinq"); 3 list.add("Portal"); 4 ListIterator<String> it = list.listIterator(1); 5 System.out.println(it.next()); View Answer
Correct answer: B — Portal
- Which of the following is true about Comparator?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.util.*; 2 class EduinqComparator implements Comparator<String> { 3 public int compare(String a, String b) { 4 return b.compareTo(a); 5 } 6 } 7 public class Test { 8 public static void main(String[] args) { 9 List<String> list = Arrays.asList("Eduinq","Portal"); 10 Collections.sort(list,new EduinqComparator()); 11 System.out.println(list); 12 } 13 } View Answer
Correct answer: B — [Portal, Eduinq]
- Which of the following is true about Comparable?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 class Eduinq implements Comparable<Eduinq> { 2 String name; 3 Eduinq(String name) { this.name = name; } 4 public int compareTo(Eduinq e) { 5 return this.name.compareTo(e.name); 6 } 7 public String toString() { return name; } 8 } 9 public class Test { 10 public static void main(String[] args) { 11 java.util.List<Eduinq> list = new java.util.ArrayList<>(); 12 list.add(new Eduinq("Portal")); 13 list.add(new Eduinq("Eduinq")); 14 java.util.Collections.sort(list); 15 System.out.println(list); 16 } 17 } View Answer
Correct answer: B — [Eduinq, Portal]
- Which of the following is true about TreeSet?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 java.util.Set<String> set = new java.util.TreeSet<>(); 2 set.add("Eduinq"); 3 set.add("Portal"); 4 System.out.println(set); View Answer
Correct answer: A — [Eduinq, Portal]
- Which of the following is true about LinkedHashMap?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 java.util.LinkedHashMap<Integer,String> map = new java.util.LinkedHashMap<>(); 2 map.put(1,"Eduinq"); 3 map.put(2,"Portal"); 4 System.out.println(map); View Answer
Correct answer: A — {1=Eduinq, 2=Portal}
- Which of the following is true about WeakHashMap?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 java.util.WeakHashMap<Object,String> map = new java.util.WeakHashMap<>(); 2 Object key = new Object(); 3 map.put(key,"Eduinq"); 4 key = null; 5 System.gc(); 6 System.out.println(map.size()); View Answer
Correct answer: A — 0 (likely)
- Which of the following is true about ConcurrentHashMap?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 java.util.concurrent.ConcurrentHashMap<Integer,String> map = new java.util.concurrent.ConcurrentHashMap<>(); 2 map.put(1,"Eduinq"); 3 System.out.println(map.get(1)); View Answer
Correct answer: A — Eduinq
- Which of the following is true about LinkedList?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 java.util.LinkedList<String> list = new java.util.LinkedList<>(); 2 list.add("Eduinq"); 3 list.add("Portal"); 4 System.out.println(list.getLast()); View Answer
Correct answer: B — Portal
- Which of the following is true about Stack class?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 java.util.Stack<String> stack = new java.util.Stack<>(); 2 stack.push("Eduinq"); 3 stack.push("Portal"); 4 System.out.println(stack.pop()); View Answer
Correct answer: B — Portal
- Which of the following is true about Queue interface?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 java.util.PriorityQueue<String> pq = new java.util.PriorityQueue<>(); 2 pq.add("Eduinq"); 3 pq.add("Portal"); 4 System.out.println(pq.peek()); View Answer
Correct answer: C — Depends on natural ordering
- Which of the following is true about Collections.sort()?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 java.util.List<String> list = new java.util.ArrayList<>(); 2 list.add("Portal"); 3 list.add("Eduinq"); 4 java.util.Collections.sort(list); 5 System.out.println(list); View Answer
Correct answer: B — [Eduinq, Portal]
- Which of the following is true about Collections.reverse()?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 java.util.List<String> list = new java.util.ArrayList<>(); 2 list.add("Eduinq"); 3 list.add("Portal"); 4 java.util.Collections.reverse(list); 5 System.out.println(list); View Answer
Correct answer: B — [Portal, Eduinq]
- Which of the following is true about Collections.unmodifiableList()?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 java.util.List<String> list = java.util.Arrays.asList("Eduinq","Portal"); 2 java.util.List<String> unmod = java.util.Collections.unmodifiableList(list); 3 System.out.println(unmod.get(1)); View Answer
Correct answer: B — Portal
- Which of the following is true about Collections.synchronizedList()?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 java.util.List<String> list = new java.util.ArrayList<>(); 2 list.add("Eduinq"); 3 java.util.List<String> syncList = java.util.Collections.synchronizedList(list); 4 System.out.println(syncList.get(0)); View Answer
Correct answer: A — Eduinq
- Which of the following is true about Enumeration?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 java.util.Vector<String> v = new java.util.Vector<>(); 2 v.add("Eduinq"); 3 java.util.Enumeration<String> e = v.elements(); 4 System.out.println(e.nextElement()); View Answer
Correct answer: A — Eduinq
- Which of the following is true about Hashtable?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 java.util.Hashtable<Integer,String> ht = new java.util.Hashtable<>(); 2 ht.put(1,"Eduinq"); 3 System.out.println(ht.get(1)); View Answer
Correct answer: A — Eduinq
- Which of the following is true about ConcurrentLinkedQueue?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 java.util.concurrent.ConcurrentLinkedQueue<String> q = new java.util.concurrent.ConcurrentLinkedQueue<>(); 2 q.add("Eduinq"); 3 q.add("Portal"); 4 System.out.println(q.poll()); View Answer
Correct answer: A — Eduinq
- Which of the following is true about CopyOnWriteArrayList?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 java.util.concurrent.CopyOnWriteArrayList<String> list = new java.util.concurrent.CopyOnWriteArrayList<>(); 2 list.add("Eduinq"); 3 list.add("Portal"); 4 for(String s : list) { 5 list.add("Extra"); 6 System.out.println(s); 7 } View Answer
Correct answer: A — Eduinq, Portal
- Which of the following is true about Collections.shuffle()?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 java.util.List<String> list = new java.util.ArrayList<>(); 2 list.add("Eduinq"); 3 list.add("Portal"); 4 java.util.Collections.shuffle(list); 5 System.out.println(list); View Answer
Correct answer: C — Either order depending on shuffle