![]() ![]() Map-Reduce is a functional programming model for transforming and aggregating data. ![]() In the next two sections, we would explain how a stream pipeline is an epitome of the map-reduce paradigm, a framework for transforming and aggregating data in meaningful results. The stream operations can be performed in parallel (possibly) to boost the performance however, this feature is outside the scope of this article. Intermediate operations return a new stream of processed elements, and a terminal operation reduces or folds the elements to a result. ![]() A stream pipeline consists of a source (e.g., a collection, an array), zero or more intermediate operations (such as filter, map), and a terminal operation (such as sum, reduce, collect). The stream operations can be either intermediate or terminal. The streams support various operations like map, filter, reduce, and collect, which can be chained together to form a pipeline. mapToInt(Integer::intValue) //map to primitive intĪt the core of the Stream API, are stream interfaces (e.g., Stream, IntStream, DoubleStream), collectively known as the streams. filter((n) -> n%2 = 0) //filter even numbers For instance, the following code calculates the sum of all even numbers in a list: List ints = Arrays.asList(2,3,2,6,5,7,8) The Stream API allows programmers to concentrate on only the necessary tasks, thus eliminating the need for writing the boilerplate loops. Working on collections often requires looping over the items. The Java 8 Stream API provides classes to perform functional-style operations in a pipeline on a stream of elements. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |