フリー問題

Java SE 21 Developer Professional のフリー問題 15 / 20 問目

問題文

A pipeline is built from a list with a filter step and a map step, and the resulting stream is assigned to a variable. Nothing else is done with it. What happens?

選択肢

  1. The filter step runs immediately so that the number of remaining elements is known, and only the map step is deferred until a terminal operation arrives.
  2. An IllegalStateException is thrown as soon as the pipeline is assigned to a variable without a terminal operation, and a stream must be consumed exactly once before it goes out of scope.
  3. Neither step runs, because intermediate operations are lazy and do nothing until a terminal operation is invoked on that stream.
  4. Both steps run immediately, and the stream then holds the transformed values, which a later call can read.

解答・解説を確認するには

正解と解説の確認、回答の記録には無料登録が必要です。登録すると演習モードでフリー問題に回答し、正誤と解説をその場で確認できます。