Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to depart String by "space"

 
marshal ma
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Thanks,
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The String.split() method is a very easy way to do exactly what you want.
 
marshal ma
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ernest Friedman-Hill

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

Thanks a lot,
 
Julien Grenier
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lesson number one : Know your API
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic