Java streams was a significant improvement with Java 8. Now, Java is able to deal with streams of information flow in a functional manner. In this example, we will use stream in several small examples to show the power of the feature.
The code snippet we are using is as follows:
public class MyStreams { public static void main(String[] args) { List<Integer> numbers = new ArrayList<Integer>(); numbers.add(3); numbers.add(-1); numbers.add(3); numbers.add(17); numbers.add(7); System.out.println("Numbers greater than 2"); numbers.stream() .filter(number -> number > 2) .forEach(number -> System.out.println(number)); System.out.println("number size = " + numbers.stream().count()); Integer big = numbers.stream().max((n1,n2) -> Integer.compare(n1, ...