-2

explain the comparison with the example. can anyone explain to me the line from the book "java8 in Action" ---

every element in the collection has to be computed before it can be added to the collection.

Swati
  • 11
  • 4
  • 2
    what is not clear about this statement? – Eugene Jan 29 '19 at 09:47
  • "elements have to be computed before becoming part of the collection " – Swati Jan 29 '19 at 09:50
  • 4
    Possible duplicate of [What is the difference between Streams and Collections in Java 8](https://stackoverflow.com/questions/39432699/what-is-the-difference-between-streams-and-collections-in-java-8) – Abdelghani Roussi Jan 29 '19 at 10:07
  • if you want compute you can use `stream.map(" Whatever you want to compute").collect(......);` – soorapadman Jan 29 '19 at 10:51
  • @manfromnowhere my point is I am not clear with the statement mentioned above in case of the collection, but not of the stream in java8. – Swati Jan 30 '19 at 09:39
  • @Swati it's better always define question clearly .Since no reply so I added this point too even though out of scope. – soorapadman Jan 30 '19 at 09:43
  • @AbdelghaniRoussi here i am asking for the example to the concept – Swati Jan 30 '19 at 09:46

1 Answers1

1

I like the explanation from the book Java 8 in action, maybe it will help you too understand better the difference:

For readers who like philosophical viewpoints, you can see a stream as a set of values spread out in time. In contrast, a collection is a set of values spread out in space (here, computer memory), which all exist at a single point in time—and which you access using an iterator to access members inside a for-each loop.

Schidu Luca
  • 3,897
  • 1
  • 12
  • 27