aspose file tools
The moose likes Beginning Java and the fly likes Method to convert String[] to int[] Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Method to convert String[] to int[]" Watch "Method to convert String[] to int[]" New topic
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
    
  19

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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Method to convert String[] to int[]
 
Similar Threads
variable problem
collecting input using arrays
Please help with BufferReader.read()
Read all words from a text file into an array
How to find a if a file exists by extention only?