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.281Medium

Which collection allows duplicate keys in Java?

Q.282Medium

What is the initial capacity of a HashMap in Java?

Q.283Easy

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

Q.284Medium

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

Q.285Medium

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

Q.286Medium

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

Q.287Medium

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

Q.288Hard

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

Q.289Hard

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

Q.290Medium

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

Q.291Easy

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

Q.292Easy

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.293Medium

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.294Easy

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

Q.295Hard

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.296Medium

Which of the following statements is true about PriorityQueue?

Q.297Medium

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

Q.298Medium

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.299Medium

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.300Hard

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