| Author |
Method to convert String[] to int[]
|
Sandeep Swaminathan
Ranch Hand
Joined: Apr 23, 2008
Posts: 52
|
|
Very basic question:
I'm trying to get input from the user in an array (in a method) using 'for' loop construct
sample[count] & sampleStr[count] are instance variables that I declare in the beginning
1. My doubt is can we use BufferedReader to get input in an array or is there any other efficient way?
2. How to convert string[] to int[]?
|
Music is all around us. All you have to do is just LISTEN to it,
Sandeep Swaminathan
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16815
|
|
I don't think there is a convenience method for this in the core API. You'll have to instantiate the int array, and parse each element of the string array to the int array.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Sandeep Swaminathan
Ranch Hand
Joined: Apr 23, 2008
Posts: 52
|
|
Ok. So you meant to say something like this right?
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
|
That's the way I would have done it, although I might have named the method "toIntArray"; the StringArray part can be deducted from the parameter list.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: Method to convert String[] to int[]
|
|
|