You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Float class in Java is a wrapper class for the primitive float type. It provides utility methods to work with single-precision floating-point numbers and is part of the java.lang package.
Key Features of the Float Wrapper Class
Boxing and Unboxing: Automatic conversion between primitive types and the Float wrapper class.
Constants: The class provides constants like MAX_VALUE, MIN_VALUE, POSITIVE_INFINITY, etc.
Utility Methods: Methods for parsing, converting, and performing mathematical operations on float values.
Float Wrapper Class Operations
Arithmetic Operations
Operation
Symbol
Example
Addition
+
floatValue + floatValue
Subtraction
-
floatValue - floatValue
Multiplication
*
floatValue * floatValue
Division
/
floatValue / floatValue
Modulo
%
floatValue % floatValue
Relational Operations
Operation
Symbol
Example
Equal to
==
floatValue == floatValue
Not equal to
!=
floatValue != floatValue
Greater than
>
floatValue > floatValue
Less than
<
floatValue < floatValue
Greater than or equal to
>=
floatValue >= floatValue
Less than or equal to
<=
floatValue <= floatValue
Static Methods
Method
Description
Example
compare(float f1, float f2)
Compares two float values.
Float.compare(3.2f, 4.1f) → Returns -1
parseFloat(String s)
Parses a String as a primitive float.
Float.parseFloat("3.14") → Returns 3.14f
toHexString(float f)
Converts a float to its hexadecimal string representation.