Java – How to convert Long to other primitive numeric data types ?
Problem Statement
You need convert a long value to other numeric data types in java.
Solution
Use the Long wrapper class which exposes methods like byteValue , shortValue , intValue etc.
Below is a sample code snipper demonstrating the usage of the same.
public class Main { public static void main(String[] args) { System.out.println("Abundantcode.com Java Tutorials"); Long input = new Long("76"); // Convert Long to short value short output1 = input.shortValue(); System.out.println(output1); // Convert Long to int int output2 = input.intValue(); System.out.println(output2); // Convert long to double double output3 = input.doubleValue(); System.out.println(output3); } }
The output for the above program is
Abundantcode.com Java Tutorials
76
76
76.0
2 Comments
[…] you looking at implementing the full text search with in your website ? . In this blog post , we will list out the top 10 open source full text […]
[…] you looking at implementing the full text search with in your website ? . In this blog post , we will list out the top 10 open source full text […]