• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Functional Programming inJava

 
Ranch Hand
Posts: 576
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
I'm sure this is covered in your book but was wondering what you consider the biggest advantage of using the streams API over the collections API for handling data ?

A sample use case:
You want to iterate through a list of email addresses . If the the email is in a second list , you  send an email then handle a bounced email or do further processing after the mail is sent if not bounced.

For me, it would make more sense to use an iterator for that.

thanks,
Paul
 
Marshal
Posts: 79786
382
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But a Stream does use an Iterator. The iteration is hidden from the programmer, so the boilerplate code involved in writing a loop becomes unnecessary.
 
Author
Posts: 135
10
  • Likes 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Paul The streams provide an internal iterator so you can focus on what do to and let the underlying code take care of stepping over the elements.

The overall benefit is reduced complexity and the code begins to read like the problem statement.

A good way get a feel for this is to create both the imperative style version and the functional style version and compare the pros and cons. Then pick the one that makes the most sense or you feel the most comfortable with (however, don't let your familiarity with one over the other taint your judgement).
 
paul nisset
Ranch Hand
Posts: 576
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Venkat .
That a good suggestion. Familiarity is a temptation . I've also seen in it the code of people I've worked with.
ie. A new project but coding style is  15 years old.
 
If I had asked people what they wanted, they would have said faster horses - Ford. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic