Beginning Java 8 Streams

One of the most useful feature in Java 8 is the Stream API
The Streams API extends the Collections API with methods to convert and filter items in a collection. Here is a simple example and explanation

In this example we take a list of words and
1. Convert the list to a Stream using .stream()
2. filter the list looking for words that start with “c”
3. Change all the words to uppercase
4. sort the list using sorted()
5. finish the processing of the stream by collecting the results into a list.

Map
At their simplest Mapping functions convert something into something else. In many programming languages, Map is the name of a higher-order function that applies a given function to each element of a list, returning a list of results. It is often called apply-to-all when considered in functional form.

In mathematics a Map is an operation that takes a function mapping a domain D to a range R, and a list of elements of D. It then produces a list of elements of R.

The Map function in the Streams API produces a list with the same number of elements as the input list.

Here is an example using the Map function

<code>
 items.stream().map( item -> item.toUpperCase()
</code>

Here is a full example from my GitHub account.

The examples I have are draw almost directly for a presentation given by Dr. Venkat Subramaniam and a blog post written by Benjamin Winterberg. I have provided link to both below. Additionally I have provided a link to an excellent pictorial representation of the various stream operation is from Martin Fowler.

Resources
Dr. Venkat Subramaniam Java 8 Streams Presentation
http://java.dzone.com/articles/devnexus-keynote-programming

Benjamin Winterberg blog 
http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/

Martin Fowler 
http://martinfowler.com/articles/collection-pipeline/

Manning Java 8 in Action Book
http://manning.com/