Skip to Content

Java String valueOf 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. Java String valueOf example.
  3. This Java String valueOf example describes how various java primitives and Object
  4. are converted to Java String object using String valueOf method.
  5. */
  6.  
  7. public class JavaStringValueOfExample{
  8.  
  9.   public static void main(String args[]){
  10.  
  11.   /*
  12.   Java String class defines following methods to convert various Java primitives to
  13.   Java String object.
  14.   1) static String valueOf(int i)
  15.   Converts argument int to String and returns new String object representing
  16.   argument int.
  17.   2) static String valueOf(float f)
  18.   Converts argument float to String and returns new String object representing
  19.   argument float.
  20.   3) static String valueOf(long l)
  21.   Converts argument long to String and returns new String object representing
  22.   argument long.
  23.   4) static String valueOf(double i)
  24.   Converts argument double to String and returns new String object representing
  25.   argument double.
  26.   5) static String valueOf(char c)
  27.   Converts argument char to String and returns new String object representing
  28.   argument char.
  29.   6) static String valueOf(boolean b)
  30.   Converts argument boolean to String and returns new String object representing
  31.   argument boolean.
  32.   7) static String valueOf(Object o)
  33.   Converts argument Object to String and returns new String object representing
  34.   argument Object.
  35.   */
  36.  
  37.   int i=10;
  38.   float f = 10.0f;
  39.   long l = 10;
  40.   double d=10.0d;
  41.   char c='a';
  42.   boolean b = true;
  43.   Object o = new String("Hello World");
  44.  
  45.   /* convert int to String */
  46.   System.out.println( String.valueOf(i) );
  47.   /* convert float to String */
  48.   System.out.println( String.valueOf(f) );
  49.   /* convert long to String */
  50.   System.out.println( String.valueOf(l) );
  51.   /* convert double to String */
  52.   System.out.println( String.valueOf(d) );
  53.   /* convert char to String */
  54.   System.out.println( String.valueOf(c) );
  55.   /* convert boolean to String */
  56.   System.out.println( String.valueOf(b) );
  57.   /* convert Object to String */
  58.   System.out.println( String.valueOf(o) );
  59.  
  60.   }
  61.  
  62. }
  63.  
  64. /*
  65. OUTPUT of the above given Java String valueOf Example would be :
  66. 10
  67. 10.0
  68. 10
  69. 10.0
  70. a
  71. true
  72. true
  73. Hello World
  74. */