Skip to Content

Java String to String Array 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 to String Array Example
  3.   This Java String to String Array example shows how to convert String object to String array in
  4.   Java using split method.
  5.  */
  6.  
  7. public class JavaStringToStringArrayExample {
  8.        
  9.         public static void main(String args[]){
  10.                
  11.                 //String which we want to convert to String array
  12.                 String str = "Java String to String Array Example";
  13.                
  14.                 /*
  15.                  * To convert String object to String array, first thing
  16.                  * we need to consider is to how we want to create array.
  17.                  *
  18.                  * In this example, array will be created by words contained
  19.                  * in the original String object. So, first element of array
  20.                  * will contain "java", second will contain "String" and so on.
  21.                  *
  22.                  * To convert String to String array, use
  23.                  * String[] split(String delimiter) method of Java String
  24.                  * class as given below.
  25.                  */
  26.                
  27.                 String strArray[] = str.split(" ");
  28.                
  29.                 System.out.println("String converted to String array");
  30.                
  31.                 //print elements of String array
  32.                 for(int i=0; i < strArray.length; i++){
  33.                         System.out.println(strArray[i]);
  34.                 }
  35.         }
  36.        
  37. }
  38.  
  39. /*
  40. Output of Java String to String Array Example would be
  41. String converted to String array
  42. Java
  43. String
  44. to
  45. String
  46. Array
  47. Example
  48. */