fosho fosho - 1 year ago 45
Java Question

Split string into individual words Java

I would like to know how to split up a large string into a series of smaller strings or words.
For example:

I want to walk my dog.

I want to have a string:
another string:
, etc.

How would I do this?

Answer Source

Use split() method


String s = "I want to walk my dog";

 String[] arr = s.split(" ");    

 for ( String ss : arr) {