aspose file tools*
The moose likes Beginning Java and the fly likes Is there a way to explode a string to format the different chars? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Is there a way to explode a string to format the different chars?" Watch "Is there a way to explode a string to format the different chars?" New topic
Author

Is there a way to explode a string to format the different chars?

sabin mash
Greenhorn

Joined: Aug 31, 2010
Posts: 11
I am working on an assignment t hat does not allow arrays or arraylists . I want to take a string of 100 random numbers, that looks like this "23 5 87 48 11 8 31", and format it into 5 columns. These numbers are coming from a tree when the tree is created. normally I would take each random number and put it into an array, put that array into a tostring method using modulus operator to print each array value on each line.

Because I can't use arrays, I need to explode the string, or somehow cut it up into something that's not an array. is this possible in java?

sorry for such a newbie question, thank you in advance.
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
By explode, I believe you mean separate the numbers in the String. You can wrap the String inside a Scanner and use the Scanner's hasNext() and next() methods to loop and print the numbers in a desired way.
 
jQuery in Action, 2nd edition
 
subject: Is there a way to explode a string to format the different chars?