- Java.lang Package classes
- Java.lang - Home
- Java.lang - Boolean
- Java.lang - Byte
- Java.lang - Character
- Java.lang - Character.Subset
- Java.lang - Character.UnicodeBlock
- Java.lang - Class
- Java.lang - ClassLoader
- Java.lang - Compiler
- Java.lang - Double
- Java.lang - Enum
- Java.lang - Float
- Java.lang - InheritableThreadLocal
- Java.lang - Integer
- Java.lang - Long
- Java.lang - Math
- Java.lang - Number
- Java.lang - Object
- Java.lang - Package
- Java.lang - Process
- Java.lang - ProcessBuilder
- Java.lang - Runtime
- Java.lang - RuntimePermission
- Java.lang - SecurityManager
- Java.lang - Short
- Java.lang - StackTraceElement
- Java.lang - StrictMath
- Java.lang - String
- Java.lang - StringBuffer
- Java.lang - StringBuilder
- Java.lang - System
- Java.lang - Thread
- Java.lang - ThreadGroup
- Java.lang - ThreadLocal
- Java.lang - Throwable
- Java.lang - Void
- Java.lang Package extras
- Java.lang - Interfaces
- Java.lang - Errors
- Java.lang - Exceptions
- Java.lang Package Useful Resources
- Java.lang - Useful Resources
- Java.lang - Discussion
Java - Float valueOf(float) method
Description
The Java Float valueOf(float f) method returns a Float instance representing the specified float value f.
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 a Float instance representing f.
Exception
NA
Example 1
The following example shows the usage of Float valueOf() method to get a Float object of a float value. We've initialized one Float object with a positive float using valueOf() method. Then we're printing the string representation value of the object.
package com.tutorialspoint; public class FloatDemo { public static void main(String[] args) { Float f1 = Float.valueOf(6.5f); // print the Float instance representing the specified float value System.out.println("Value = " + f1); } }
Output
Let us compile and run the above program, this will produce the following result −
Value = 6.5
Example 2
The following example shows the usage of Float valueOf() method to get a Float object of a float value. We've initialized one Float object with a negative float using valueOf() method. Then we're printing the string representation value of the object.
package com.tutorialspoint; public class FloatDemo { public static void main(String[] args) { Float f1 = Float.valueOf(-6.5f); // print the Float instance representing the specified float value System.out.println("Value = " + f1); } }
Output
Let us compile and run the above program, this will produce the following result −
Value = -6.5
Example 3
The following example shows the usage of Float valueOf() method to get a Float object of a float value. We've initialized one Float object with a negative zero float using valueOf() method. Then we're printing the string representation value of the object.
package com.tutorialspoint; public class FloatDemo { public static void main(String[] args) { Float f1 = Float.valueOf(-0.0f); // print the Float instance representing the specified float value System.out.println("Value = " + f1); } }
Output
Let us compile and run the above program, this will produce the following result −
Value = -0.0
Example 4
The following example shows the usage of Float valueOf() method to get a Float object of a float value. We've initialized one Float object with a positive zero float using valueOf() method. Then we're printing the string representation value of the object.
package com.tutorialspoint; public class FloatDemo { public static void main(String[] args) { Float f1 = Float.valueOf(0.0f); // print the Float instance representing the specified float value System.out.println("Value = " + f1); } }
Output
Let us compile and run the above program, this will produce the following result −
Value = 0.0