tags:

views:

56

answers:

2

I want to ask the user for input in console. He'll be writing down two numbers separated by a single space.

In Java is there something like the C# Split() method I can use?

Thank you!

+2  A: 

Yes, there is: String.split. Note that it takes a regex as the parameter though. Alternatively you could use a StringTokenizer or a Scanner.

Jon Skeet
It does take regex, but `String.split(" ")` would work fine in his case.
webdestroya
@webdestroya: Yup, it was more as a warning for future changes. In particular, trying to split on "." is likely to catch out more than a few unwary devs :)
Jon Skeet
@Jon - Ah yes, good call on warning for the future.
webdestroya
+1  A: 

There is a split() method in String class.

String.split();
giri