Java Stream How to - Create Lambda Function to convert Celsius to Fahrenheit








Question

We would like to know how to create Lambda Function to convert Celsius to Fahrenheit.

Answer

import java.util.function.Function;
//  w w  w.j  av  a  2s .  co m
public class Main {

  public static void main(String[] args) {

    Function<Integer,Double> centToFahrenheitInt = x -> new Double((x*9/5)+32);
    double fahrenheit = centToFahrenheitInt.apply(100);
    System.out.println("Centigrade to Fahrenheit: "+fahrenheit);
  }

}

The code above generates the following result.