Java Float Wrapper Class

Java 8Object Oriented ProgrammingProgramming

Float is a wrapper class provided to wrap float primitive value.

Let us create a Float object with float primitive.

// float primitive
float myFloat = 24.22f;
// Float object
Float obj1 = new Float(myFloat);

Let us now create a Float object from string.

Float obj2 = new Float("39.87");

The following is an example that displays both the ways discussed above with output.

Example

 Live Demo

import java.lang.*;
public class Demo {
   public static void main(String args[]) {
      float myFloat = 24.22f;
      Float obj1 = new Float(myFloat);
      System.out.println(obj1);
      Float obj2 = new Float("39.87");
      System.out.println(obj2);
   }
}

Output

24.22
39.87
raja
Published on 10-Dec-2018 08:33:49
Advertisements