• Post Reply Bookmark Topic Watch Topic
  • New Topic

Split into int array  RSS feed

 
Ranch Hand
Posts: 832
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to pass in a string into my applet (not really an applet specific question) that is delimited by (let's say tilde ~). How can I easily split that string up and assign it to an int array? Any suggestions would be appreciated. Various approaches would be interesting to see as well. Thanks.
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several ways to split a string - did you check the API?

once you do that, you'll have an array of strings. you would then need to parse those into ints, and then stick them into your array.

What have you tried so far?
 
Rob Hunter
Ranch Hand
Posts: 832
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without looping is there no alternative? I was hoping to be able to somehow split and cast that String array into an int array. Is that possible?
 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. You can split the String[] easily; if you go through the String class, you will find methods which split easily. But each member of that array has to be parsed to an int; you can't cast or reassign it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!