I need to split my String by spaces. For this I tried:
str = "Hello I'm your String";
String[] splited = str.split(" ");
But it doesn't seem to work.
I need to split my String by spaces. For this I tried:
str = "Hello I'm your String";
String[] splited = str.split(" ");
But it doesn't seem to work.
Use
Stringutils.split()
to split the string by whites paces. For exampleStringUtils.split("Hello World")
returns "Hello" and "World";In order to solve the mentioned case we use split method like this
when we print the split array the output will be :
Hello
I'm
your
String
For complete example demo check here
if somehow you don't wanna use String split method then you can use StringTokenizer class in Java as..
I do believe that putting a regular expression in the str.split parentheses should solve the issue. The Java String.split() method is based upon regular expressions so what you need is:
Here is a method to trim a String that has a "," or white space
Very Simple Example below:
Hope it helps.
Try
http://download.oracle.com/javase/tutorial/essential/regex/pre_char_classes.html