Java.lang.Float.valueOf() Method

Advertisements


Description

The java.lang.Float.valueOf(float f) method returns a Float instance representing the specified float value.

Declaration

Following is the declaration for java.lang.Float.valueOf() method

public static Float valueOf(float f)

Parameters

  • f -- This is the float value.

Return Value

This method returns a Float instance representing f.

Exception

  • NA

Example

The following example shows the usage of java.lang.Float.valueOf() method.

package com.tutorialspoint;

import java.lang.*;

public class FloatDemo {

   public static void main(String[] args) {

     Float f = new Float("4.5");
   
     // returns a Float instance representing the specified float value 
     System.out.println("Value = " +  f.valueOf(2.75f));
   }
}  

Let us compile and run the above program, this will produce the following result:

Value = 2.75



Advertisements
Advertisements