![]() ![]() The stream() method generates one sequential stream. If we consider the above example, we can generate one parallel stream instead of a sequential stream. We can use a stream map with a parallel stream. In our case, we are printing out the value of each item of the new stream. It takes one action that performs on each element of the stream. map() function takes one mapper function to apply on each stream element. ![]() Then we are using one transform function to convert each stream item to our desired result and finally, we are using forEach to print out the formatted value. Latitudes.stream().map(lat -> lat.toString() + " degrees").forEach(System.out::println) įirst, we are converting the list to a stream. We are iterating through the list, converting each item to string and appending ‘degrees’ to the end.If we write the same process using the stream map(), it will look like below: import Here, 'latitudes' is the list of latitudes. For that, we will loop through the list of latitudes, convert each to String and append ‘degrees’ to the end. Suppose we have one list of latitudes of positions in Double format and we want to make them more readable by appending ‘degrees’ to the end of each. If we want any modification to the list, we can do it inside the loop block. The traditional approach to iterate through a list is by using a for loop or any other loop.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |