This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Splitting a string to smaller strings. 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 "Splitting a string to smaller strings." Watch "Splitting a string to smaller strings." New topic

Splitting a string to smaller strings.

James Palmer
Ranch Hand

Joined: Mar 15, 2004
Posts: 36
Hello, i have a big string with lots of words in it and i want to find a way to split this string into separate words.This probably means that whenever the program finds a space it means that this is a new word and should make a new string for that one until it meets a space again.Particularly i want to use a tokenizer to do this.For example the string "I have a cat" should be split in 4 strings."I" "have" "a" "cat".Can anyone help?
john smith
Ranch Hand

Joined: Mar 04, 2004
Posts: 75
From the API javadoc:
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
You can learn more about the StringTokenizer here

- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
David Peterson
Ranch Hand

Joined: Oct 14, 2001
Posts: 154
Alternatively use the split() method of String class.
I agree. Here's the link:
subject: Splitting a string to smaller strings.
It's not a secret anymore!