Reputation: 9363
What I need to do is that I have a series of lines of integers and have to read them from console. I have adopted the following method. I read a line and then split it using the delimiter as space, collect the integers into a string array and then typecast each of the element of the string array. I find this method very cumbersome. Is there any other simpler method to achieve the same in Java?
Upvotes: 0
Views: 2850
Reputation: 4891
Look into using something like java.io.Scanner, and its methods for grabbing variables of various types.
Upvotes: 0
Reputation: 23268
Scanner in = new Scanner(theLine);
while (in.hasNextInt())
add in.nextInt() to arraylist or something
Upvotes: 4