tags:

views:

86

answers:

3

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
Quick, correct, precise, with link to the docs. This is a winner.
Michael Myers
A: 

String.split should be all you need.

String myString = "hello hallo tjena hej tere";
String[] words = myString.split(" ");
Mike Clark
A: 

commons-lang has a better implementation with a common contract.

String[] splits = StringUtils.split("hello hallo tjena hej tere");
Carl
I think String.split() is sufficent and doesn't need to include any other APIs.
Helper Method
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
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
C'mon this answer isn't that bad that it deserves so many downvotes?
Alfred