Quiz Space

Programming Concepts using Java · Quiz 2 · 16 Mar 2025 · January 2025 term

Question 12: Consider the Java code given below. What will the output…

Question 12

+7 marksOne correct option

Consider the Java code given below.

java
import java.util.*;
public class SetExample {
public static void main(String[] args) {
LinkedList<String> list = new LinkedList<String>();
list.add("Apple");
list.add("Samsung");
list.add("Nokia");
list.add("Samsung");
Set<String> set1 = new LinkedHashSet<String>();
Set<String> set2 = new TreeSet<String>();
for (String str : list) {
set1.add(str);
set2.add(str);
}
for (String str : set1) {
System.out.print(str + " ");
}
System.out.println();
for (String str : set2) {
System.out.print(str + " ");
}
}
}

What will the output be?

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • A

Question 12 of 15 in the IIT Madras BS Programming Concepts using Java (Java) Quiz 2 paper sat on 16 Mar 2025, in the January 2025 term (IIT M DIPLOMA AN EXAM QDD2 16 Mar 2025). It carries 7 marks.

More questions from this paper

  1. Q1Consider the Java code given below that prints the maximum element of a set. From among the options, identify the appro…
  2. Q2Consider the Java code given below. Choose the correct option.
  3. Q3The following code maps a set of patients to the number of visits they have made to a hospital and categorizes the pati…
  4. Q4Consider the code given below. What will the output be?
  5. Q5Consider the following Java code. Choose the correct option to be filled in place of LINE 1 so that the output is:\ [Ta…
  6. Q6Consider the following Java code. Choose the correct option.
  7. Q7Consider the Java code given below. Choose the correct option.
  8. Q8Consider two Java files located in different packages as shown below. A.java B.java Choose the correct option.
  9. Q9Consider the Java code given below. Identify the first assert statement that throws the AssertionError when the class i…
  10. Q10Consider the Java code given below. Identify the appropriate option to fill in place of LINE 1 such that the output is:…
  11. Q11Method Stream.iterate(e, f) returns an infinite sequential ordered Stream produced by iterative application of a functi…
  12. Q13Consider the Java code given below. Choose all the options which can be used in place of ARG in LINE 1 so that the code…
  13. Q14The Java code given below should print the names of water filters whose flow rate falls within the range of 5.0 to 15.0…
  14. Q15Consider the Java code given below. How does class MarksExample look after type erasure?