What is the number wrapper class and its methods in Java?

Java 8Object Oriented ProgrammingProgramming

The Number class (abstract) of the java.lang package represents the numeric values that are convertible to primitive types byte, double, float, int, long, and short.

Following are the method provided by the Number class of the java.lang package.

Sr.No Method & Description
1

byte byteValue()

This method returns the value of the specified number as a byte.

2

abstract double doubleValue()

This method returns the value of the specified number as a double.

3

abstract float floatValue()

This method returns the value of the specified number as a float.

4

abstract int intValue()

This method returns the value of the specified number as a int.

5

abstract long longValue()

This method returns the value of the specified number as a long.

6

short shortValue()

This method returns the value of the specified number as a short.

Example

Live Demo

public class NumberClassExample {
   public static void main(String args[]){
      Number num = new Integer("25");
      System.out.println("Float value of the number: "+num.floatValue());
      System.out.println("Double value of the number: "+num.doubleValue());
      System.out.println("Long value of the number: "+num.longValue());
      System.out.println("Byte value of the number: "+num.byteValue());
      System.out.println("Double value of the number: "+num.doubleValue());
      System.out.println("Short value of the number: "+num.shortValue());
   }
}

Output

Float value of the number: 25.0
Double value of the number: 25.0
Long value of the number: 25
Byte value of the number: 25
Double value of the number: 25.0
Short value of the number: 25
raja
Published on 08-Jan-2018 05:07:04
Advertisements