Java Integer floatValue() method
The floatValue() method of Integer class returns a float value for this Integer after a widening primitive conversion.
Syntax
public float floatValue()
Parameters
NA
Specified by
This method is specified by floatValue in class Number
Return Value
This method returns the numeric value of this object after conversion to type float.
Example 1
public class JavaIntegerFloatValueExample1 { public static void main(String[] args) { Integer val1=980; Integer val2=102; //returns a float value for this Integer float val=val1.floatValue(); System.out.println("1. Float value : "+val); System.out.println("2. Float value : "+val2.floatValue()); } }
Output
Float value : 980.0 Float value : 102.0
Example 2
public class JavaIntegerFloatValueExample2 { public static void main(String[] args) { Integer val1=98; Integer val2=102; //returns a float value for this Integer Float val=val1.floatValue(); System.out.println("Float value : "+val); //calling float class methods int hashCode=val.hashCode(); System.out.println("Hash code for float value "+ val +" is : "+hashCode); } }
Output
Float value : 98.0 Hash code for float value 98.0 is : 1120141312
Example 3
public class JavaIntegerFloatValueExample3 { public static void main(String[] args) { //val1 is an int primitive data type object, it can not be used to call Integer class floatValue method int val1=7; Integer val2=Integer.MAX_VALUE;; System.out.println("1. "+val1.floatValue()); System.out.println("2. "+val2.floatValue()); } }
Output
Error:(8, 39) java: int cannot be dereferenced