Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Beginning Java and the fly likes Splitting a string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Splitting a string" Watch "Splitting a string" New topic

Splitting a string

Ben Roy
Ranch Hand

Joined: Nov 01, 2000
Posts: 70
I was just posting a question regarding the java.lang.String.split() method when I figured out that I was using 1.3 and it's only available in 1.4. So that leaves me the question of whether there is some way to do this (split a comma separated list into an array) in 1.3 other than manually write my own function to do it. Anyone got a quick solution?
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
You'll want to check out the StringTokenizer class. It'll give you an enumeration that you can iterate over and store into an array.
There may be another way out there but this was the first that came to mind.
hope that helps

Sun Certified Programmer for the Java� 2 Platform


Joined: Nov 20, 2001
Posts: 2
Try the split function that is found in this class:
Ben Roy
Ranch Hand

Joined: Nov 01, 2000
Posts: 70
You know it's kind of funny how sometimes the problem isn't the language...
One method was reading a recordset and dumping the information in a string, then the other was converting from a string to array. Duh...I hadn't even written the first yet, so I just rethought it and made it return String[] instead. Solved all my conversion problems and works great. Thanks for the suggestions though.
I agree. Here's the link:
subject: Splitting a string
It's not a secret anymore!