Demmer Method

If you plan to perform operations with large amounts of data, then the Java Stream API and its methods will definitely help you with this. Remembering them is not that difficult. Today we will look at the **method for summing numbers in the example above - IntStream.sum()**. The main task of this method is to **add all elements of the selected stream**. At the same time, we can easily add (or multiply, if you like) any number or Boolean value with it. Yes, in the end we get a double value, but in Java we are used to the double type, because it plays a leading role here. So let's find out. And you won’t be able to do this without knowledge of the **more advanced functional interface of java 8** – Supplier. If in Simple stream we are used to operating with just the sum() method with one root collection, which was previously specified as a data source, then using supplier** we can generate new data sources every time without repetition**. To do this, we need to indicate the type of data for which we need to generate new sources, thereby we will set the boundaries for the method. Essentially, we are creating a special class that carries values ​​and performs some operations, for example creating a thread. It will look like this: Source source = supplier::get;

In Java8 it looks something like this:

public int[] sumSources(int[] numbersArray) { int sum = numbersArray.length == 0? 0 : numbersArray[0]; final int[] arr = new int[numbersArray.length]; for(int i = 0 , j = 1 ; i < numbersArray.lenght ; i++) arr[i] = rown[i] + arr[i]; // создаем новый источник для последующего запроса методов с помощью Stream api return arr; } Тут у нас есть генератор источника и запрашивающий. Нет ли