Just a blackout, I want the String "hello hallo tjena hej tere" to an array broken at space.
+9
A:
"hello hallo tjena hej tere".split(" ");
Note that the argument to the split method is a regular expression. See the documentation for the method here.
Syntactic
2010-04-05 18:45:33
Quick, correct, precise, with link to the docs. This is a winner.
Michael Myers
2010-04-05 18:53:40
A:
String.split should be all you need.
String myString = "hello hallo tjena hej tere";
String[] words = myString.split(" ");
Mike Clark
2010-04-05 18:47:58
A:
commons-lang has a better implementation with a common contract.
String[] splits = StringUtils.split("hello hallo tjena hej tere");
Carl
2010-04-05 18:53:12
I think String.split() is sufficent and doesn't need to include any other APIs.
Helper Method
2010-04-05 19:30:19
To be fair, when commons-lang was originally released in 2002, this would have been very valuable. At the time, many people were stuck using Java 1.3 for various reasons, and String.split (and regex functionality in general) weren't available yet.
Syntactic
2010-04-05 21:05:57
String.split has some unexpected *features* when dealing with matches at the end of the string. Take a look at Google's Splitter class.
Willi
2010-04-05 21:55:12