iGET

Java Programming - MCQ Practice Questions

Practice free Java Programming multiple-choice questions with detailed answers and explanations. Perfect for competitive exam preparation.

958 questions | 100% Free

Q.81Medium

Which collection allows duplicate keys in Java?

Q.82Medium

What is the initial capacity of a HashMap in Java?

Q.83Easy

Which method returns true if the map contains the specified value?

Q.84Medium

What happens when you add a null key to a HashMap?

Q.85Medium

Which collection implementation is best for frequent insertions and deletions at both ends?

Q.86Medium

What is the purpose of the fail-fast iterator in Collections?

Q.87Medium

Consider a TreeMap with Integer keys. What will headMap(10) return?

Q.88Hard

Which method in Collections can create a thread-safe Map from a non-thread-safe Map?

Q.89Hard

What is the main advantage of EnumSet over HashSet when working with Enum constants?

Q.90Medium

Which collection interface guarantees that elements are stored in a sorted order with no duplicates?

Q.91Easy

Which of the following collections maintains insertion order while allowing fast random access?

Q.92Easy

What will be the output of the following code? Set<Integer> set = new TreeSet<>(); set.add(5); set.add(2); set.add(8); set.add(2); System.out.println(set.size());

Q.93Medium

Which collection would you use if you need to maintain a sorted order of elements and also need O(log n) insertion/deletion time complexity?

Q.94Easy

What will happen when you execute: Map<String, String> map = new HashMap<>(); map.put("key", null); System.out.println(map.get("key"));

Q.95Hard

Consider this code: List<String> list = new CopyOnWriteArrayList<>(); list.add("A"); list.add("B"); Iterator<String> itr = list.iterator(); list.add("C"); System.out.println(itr.next());

Q.96Medium

Which of the following statements is true about PriorityQueue?

Q.97Medium

What is the time complexity of get() operation on a LinkedHashMap with n elements?

Q.98Medium

Which collection interface should be used if you need both key-value pairing and need to iterate in the order of keys' natural ordering?

Q.99Medium

What will be printed? Queue<Integer> queue = new LinkedList<>(); queue.add(10); queue.add(20); queue.add(30); System.out.println(queue.poll()); System.out.println(queue.peek());

Q.100Hard

In Java 2024, if you need a collection that automatically removes entries based on garbage collection patterns, which would you choose?