I asked a very similar question yesterday, so you might want to check that out. I gave a solution to your problem, but my question was about having a more elegant/concise way to achieve the same.
If you generate a List
, there is nothing lazy about it, your whole result is parsed and returned. However, even if you use a Stream
, for performance reasons, you should try to reduce the number of rows already in your query. For example, if you are only interested in the first n rows, you should add limit n
, otherwise the database will still be queried for all rows, and you will just save a little time by not parsing them when using Stream
instead of List
.