Convert Long to numeric primitive data types example /*   Convert Long to numeric primitive data types example   This example sh...

Convert Long to numeric primitive data types example

03:06 PASSOVE INCOME 0 Comments

Convert Long to numeric primitive data types example

  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. public class LongToNumericPrimitiveTypesExample {
  12.   public static void main(String[] args) {
  13.     Long lObj = new Long("10");
  14.     //use byteValue method of Long class to convert it into byte type.
  15.     byte b = lObj.byteValue();
  16.     System.out.println(b);
  17.    
  18.     //use shortValue method of Long class to convert it into short type.
  19.     short s = lObj.shortValue();
  20.     System.out.println(s);
  21.    
  22.     //use intValue method of Long class to convert it into int type.
  23.     int i = lObj.intValue();
  24.     System.out.println(i);
  25.    
  26.     //use floatValue method of Long class to convert it into float type.
  27.     float f = lObj.floatValue();
  28.     System.out.println(f);
  29.     //use doubleValue method of Long class to convert it longo double type.
  30.     double d = lObj.doubleValue();
  31.     System.out.println(d);
  32.   }
  33. }
  34. /*
  35. Output of the program would be :
  36. 10
  37. 10
  38. 10
  39. 10.0
  40. 10.0
  41. */

    0 comments: