Skip to Content

Convert Long to numeric primitive data types example

  • strict warning: Non-static method view::load() should not be called statically in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/views.module on line 906.
  • strict warning: Declaration of views_handler_argument::init() should be compatible with views_handler::init(&$view, $options) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_argument.inc on line 0.
  • strict warning: Declaration of views_handler_filter::options_validate() should be compatible with views_handler::options_validate($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter::options_submit() should be compatible with views_handler::options_submit($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter_boolean_operator::value_validate() should be compatible with views_handler_filter::value_validate($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter_boolean_operator.inc on line 0.
  • strict warning: Declaration of views_plugin_style_default::options() should be compatible with views_object::options() in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_style_default.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_validate() should be compatible with views_plugin::options_validate(&$form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_row.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_submit() should be compatible with views_plugin::options_submit(&$form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_row.inc on line 0.

  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. */