Imagine you have a collection of temperature readings in Celsius that you need to convert to Fahrenheit. Prior to Java 8 you would be required to iterate through the collection and convert each temperature reading individually. In Java 8, the conversion of each temperature can be done in just one line of code. The key to achieving this goal is to use the map method of the Stream class. This method maps (i.e., translates) each element of a collection based on a given lambda or method reference. To learn how to map elements using the map method, follow these four steps.

Leave a Reply

Your email address will not be published. Required fields are marked *