Quiz Space

Programming Concepts using Java · End Term · 3 Sept 2023 · May 2023 term · Set QPD1-S2

Question 21: Consider the code given below. What will the output be?

Question 21

+5 marksOne correct option

Consider the code given below.

java
import java.util.*;
public class TestHigh {
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
list.add("RAT");
list.add("SKY");
list.add("FLY");
list.add("EAGLE");
list.add("LEMON");
list.add("VK");
list.add("MSD");
list.stream().takeWhile(s->s.length()==3)
.forEach(s -> System.out.print(s+" "));
System.out.println();
list.stream().dropWhile(s->s.length()==3)
.forEach(s -> System.out.print(s+" "));
}
}

What will the output be?

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

Correct answer

  • C

Question 21 of 23 in the IIT Madras BS Programming Concepts using Java (Java) End Term paper sat on 3 Sept 2023, in the May 2023 term (IIT M DIPLOMA ET1 EXAM QPD1 S2 03 Sep). It carries 5 marks.

More questions from this paper

  1. Q1Method Stream.iterate(e, f) returns an infinite sequential ordered Stream produced by iterative application of a functi…
  2. Q2Consider the following java code What will the output be?
  3. Q3Consider the java code given below What will the output be?
  4. Q4Consider the Java code given below.\ You may make use of the method description given below.\ getOrDefault(Object key, …
  5. Q5Consider the Java code given below Choose the correct option(s) to be filled in place of CODE BLOCK so that the program…
  6. Q6Consider the following java code What will the output be?
  7. Q7Consider the following java code Identify the first assert statement that throws the AssertionError when the class is e…
  8. Q8Consider the code given below. Choose the correct option.
  9. Q9Consider the Java code given below Choose the correct option to be filled in place of CODE BLOCK so that the program ge…
  10. Q10Consider the code given below.\ Assume that, before execution of the given code, the files "f1.txt" and "f2.txt" have t…
  11. Q11Consider the code given below. What will the output be?
  12. Q12Consider the code given below. What will the output be?
  13. Q13Consider the Java code given below Choose the correct option(s) to be filled in place of LINE 1 so that the program gen…
  14. Q14Consider the three Java files given below.\ TestPack1.java: TestPack2.java: Test.java: Choose the correct option.
  15. Q15Consider the code given below. Which of the following is true about the given code?
  16. Q16Consider the Java program given below and select the correct option from among the given choices.
  17. Q17Consider the Java program given below. Initial State: window with Clear and Reload buttons, empty label.\ On clicking C…
  18. Q18Consider the following code Which of the following is/are possible output(s)?
  19. Q19Consider the code given below. Choose the correct option(s) to be filled in place of CODE BLOCK so that the output is: …
  20. Q20Consider the Java code given below. Choose the correct option.
  21. Q22Figure question
  22. Q23Consider the following java code: Identify the line/s which has/have error.