Monday Mar 24, 2014

Learn More About Streams and Collections

Lambda Expressions are a major new language feature introduced in Java SE 8. Related to that change are the Streams API and Aggregate Operations on Collections. The Collection interface now exposes methods Stream<E> stream() and Stream<E> parallelStream(), for obtaining sequential or parallel streams from an underlying collection.

Here's a quick example showing how this new API (with Lambda Expressions) would be used in place of a traditional Iterator or for loop. It obtains a stream from the underlying collection, selects only red objects, then prints out the name of each object that was matched:

myShapesCollection.stream()
.filter(e -> e.getColor() == Color.RED)
.forEach(e -> System.out.println(e.getName()));

Likewise, you could easily request a parallel stream, which might make sense if the collection is large enough and your computer has enough cores:

myShapesCollection.parallelStream()
.filter(e -> e.getColor() == Color.RED)
.forEach(e -> System.out.println(e.getName()));

Using streams enables your code focus on "what" to do (instead of "how" to do it), leaving the library free to use whatever techniques it deems most appropriate (laziness, out-of-order execution, parallelism, etc.).

For more information on Lambda Expressions and Aggregate Operations, see the following resources:

See What's New in JDK 8 for information about other new features in JDK 8.

Wednesday Sep 25, 2013

JavaOne 2013: Lambda Expressions

Many conferences and hands-on lab sessions at JavaOne 2013 today feature lambda expressions, such as the following:

For more information about lambda expressions, see the following sections in the Java Tutorials:

Preview the Streams API in the java.util.stream package in the JDK 8 Early Access documentation.

Monday Sep 23, 2013

JavaOne 2013: Jump-starting Lambda Programming and The Road to Lambda

At JavaOne 2013, Stuart Marks presented the conference " Jump-starting Lambda Programming," and Paul Sandoz and Brian Goetz presented the conference "The Road to Lambda."

To learn more about lambda, see Lambda Expressions in the Java Tutorials. The conference "Jump-starting Lambda Programming" discusses the new Stream library; see the lesson Bulk Data Operations to learn more about this library. The conference "The Road to Lambda" discusses the new parallel stream libraries; see the section Parallelism for more information.

About

Blog about Java technology documentation and news about Java releases.

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today