- 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
Convert Byte to numeric primitive data types in Java
To convert Byte to numeric primitive data types, use the following methods −
byteValue() shortValue() intValue() longValue() floatValue()
Firstly, let us declare a Byte.
Byte byteVal = new Byte("35");
Now, let us see how to convert it to long type, for a simple example.
long longVal = byteVal.longValue(); System.out.println(longVal);
In the same way, you can convert it to other primitive data types as shown in the complete example below −
Example
public class Demo { public static void main(String args[]) { // byte Byte byteVal = new Byte("35"); byte b = byteVal.byteValue(); System.out.println(b); short shortVal = byteVal.shortValue(); System.out.println(shortVal); int intVal = byteVal.intValue(); System.out.println(intVal); long longVal = byteVal.longValue(); System.out.println(longVal); float floatVal = byteVal.floatValue(); System.out.println(floatVal); double doubleVal = byteVal.doubleValue(); System.out.println(doubleVal); } }
Output
35 35 35 35 35.0 35.0
Advertisements