Convert long to numeric primitive data types example

Source: Internet
Author: User
   1.      /*   2.        Convert Long to numeric primitive data types example   3.        This example shows how a Long object can be converted into below given numeric   4.        data types   5.        - Convert Long to byte   6.        - Convert Long to short   7.        - Convert Long to int   8.        - Convert Long to float   9.        - Convert Long to double  10.      */  11.         12.      public class LongToNumericPrimitiveTypesExample {  13.         14.        public static void main(String[] args) {  15.          Long lObj = new Long("10");  16.          //use byteValue method of Long class to convert it into byte type.  17.          byte b = lObj.byteValue();  18.          System.out.println(b);  19.           20.          //use shortValue method of Long class to convert it into short type.  21.          short s = lObj.shortValue();  22.          System.out.println(s);  23.           24.          //use intValue method of Long class to convert it into int type.  25.          int i = lObj.intValue();  26.          System.out.println(i);  27.           28.          //use floatValue method of Long class to convert it into float type.  29.          float f = lObj.floatValue();  30.          System.out.println(f);  31.         32.          //use doubleValue method of Long class to convert it longo double type.  33.          double d = lObj.doubleValue();  34.          System.out.println(d);  35.        }  36.      }  37.         38.      /*  39.      Output of the program would be :  40.      10  41.      10  42.      10  43.      10.0  44.      10.0  45.      */

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.