This example will generate odd numbers from a given range. In the snippets below all odd numbers between 1 and 10 will be displayed.
Java 8
The Intstream.rangeClosed will return a range from 1 to 10. Next, a lambda expression will be used to create a java predicate that will return true if the number is odd. Passing it to IntStream.filter it will return all odd numbers for the given range.
Output
Google Guava
Using guava we will create a ContiguousSet passing in a Range from 1 to 10. We then will pass a guava predicate that will return true if the given number is odd to the Iterables.filter method to return all odd numbers within the range.