File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes how to depart String by Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to depart String by "space"" Watch "how to depart String by "space"" New topic

how to depart String by "space"

marshal ma

Joined: May 31, 2004
Posts: 23
I have a String like "it is good", I know the String is made of three words(two space between three words), I want to turn it to three String, like this:

String data1 = it;
String data2 = is;
String data3 = good;

How to do that easily?

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24195

The String.split() method is a very easy way to do exactly what you want.

[Jess in Action][AskingGoodQuestions]
marshal ma

Joined: May 31, 2004
Posts: 23
Hi Ernest Friedman-Hill

Got it, I didn't know there is such a good method.

Thanks a lot,
Julien Grenier
Ranch Hand

Joined: Sep 01, 2005
Posts: 41
Lesson number one : Know your API
Consider Paul's rocket mass heater.
subject: how to depart String by "space"
It's not a secret anymore!