Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
sabin mash
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic