- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the number wrapper class and its methods in Java?
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
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
To Continue Learning Please Login
Login with Google