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 of the following statements about Queue interface is correct?
What will be the result of executing this code? PriorityQueue<Integer> pq = new PriorityQueue<>(); pq.add(5); pq.add(3); pq.add(7); System.out.println(pq.peek());
Consider the following code. What is the behavior? Collection<String> col = new ArrayList<>(); col.add("Java"); Iterator<String> it = col.iterator(); while(it.hasNext()) { String s = it.next(); col.remove(s); }
Which collection class implements NavigableMap interface?
What is the output of the following code? List<String> list = Arrays.asList("A", "B", "C"); list.add("D"); System.out.println(list.size());
In the context of streams and collections, which method returns a Sequential Stream in Java 8+?
What is the time complexity of contains() operation in HashSet?
Which of the following is a fail-fast iterator behavior?
Consider a scenario where you need fast random access and frequent insertions in the middle. Which collection is most suitable?
What does the removeIf() method in Collection interface do?
What is the behavior of get() method in LinkedHashMap with accessOrder=true?
Consider implementing a Comparator for custom sorting in reverse order. Which approach is correct? List<Integer> list = Arrays.asList(5, 2, 8, 1);
Which Collection method was introduced in Java 9 to create immutable collections?
In a multi-threaded environment, if you need a thread-safe list that allows concurrent reads, which is optimal?
Which of the following Collection interfaces does NOT support duplicate elements?
What is the default initial capacity of a HashMap in Java?
Which collection class is synchronized by default?
What does the poll() method return when called on an empty Queue?
Which of the following correctly represents the hierarchy of Collection framework?
What is the time complexity of add() operation in ArrayList?