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
Which collection allows duplicate keys in Java?
What is the initial capacity of a HashMap in Java?
Which method returns true if the map contains the specified value?
What happens when you add a null key to a HashMap?
Which collection implementation is best for frequent insertions and deletions at both ends?
What is the purpose of the fail-fast iterator in Collections?
Consider a TreeMap with Integer keys. What will headMap(10) return?
Which method in Collections can create a thread-safe Map from a non-thread-safe Map?
What is the main advantage of EnumSet over HashSet when working with Enum constants?
Which collection interface guarantees that elements are stored in a sorted order with no duplicates?
Which of the following collections maintains insertion order while allowing fast random access?
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());
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?
What will happen when you execute: Map<String, String> map = new HashMap<>(); map.put("key", null); System.out.println(map.get("key"));
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());
Which of the following statements is true about PriorityQueue?
What is the time complexity of get() operation on a LinkedHashMap with n elements?
Which collection interface should be used if you need both key-value pairing and need to iterate in the order of keys' natural ordering?
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());
In Java 2024, if you need a collection that automatically removes entries based on garbage collection patterns, which would you choose?