- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 Short to numeric primitive data types in Java
To convert Short to numeric primitive data types, use the following methods −
byteValue() shortValue() intValue() longValue() floatValue()
Firstly, let us declare a Short.
Short shortObj = new Short("40");
Now, let us see how to convert it to long type, for a simple example.
long val5 = shortObj.longValue(); System.out.println("Long: "+val5);
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) { Short shortObj = new Short("40"); byte val1 = shortObj.byteValue(); System.out.println("Byte: "+val1); int val2 = shortObj.intValue(); System.out.println("Int: "+val2); float val3 = shortObj.floatValue(); System.out.println("Float: "+val3); double val4 = shortObj.doubleValue(); System.out.println("Double: "+val4); long val5 = shortObj.longValue(); System.out.println("Long: "+val5); } }
Output
Byte: 40 Int: 40 Float: 40.0 Double: 40.0 Long: 40
- Related Articles
- Convert Long to numeric primitive data types in Java
- Convert Byte to numeric primitive data types in Java
- Java Program to convert Double to numeric primitive data types
- Java Program to convert Java Float to Numeric Primitive Data Types
- Convert short primitive type to Short object in Java
- List out the default values of numeric and non-numeric primitive data types in Java?
- Java Program to convert String to short primitive
- Java primitive data types
- How to convert JavaScript objects to primitive data types manually?
- What are primitive data types in Java?
- Default value of primitive data types in Java
- Java Program to convert a string into a numeric primitive type using Integer.valueOf()
- C++ Program to convert primitive types to objects
- How to convert primitive data into wrapper class using Java?
- What are Primitive and Non-Primitive Data Types in JavaScript?

Advertisements