Hello fellow programmers!
I am trying to write a java program where it reads multiple lines of input.
e.g.
HELLO I ATE APPLE
APPLE IS GOOD
I ATE MORE
** There can be more lines of course.
I am trying to store every line in an ArrayList<String>
i.e. I want to be able to store the above like this
list.get(0) = "HELLO I ATE APPLE"
list.get(1) = "APPLE IS GOOD"
etc...
Scanner in = new Scanner(System.in);
ArrayList<String> inp = new ArrayList<>();
while(in.hasNextLine()) {
Scanner liner = new Scanner(in.nextLine());
while(liner.hasNext()) {
inp.add(liner.next());
}
liner.close();
}
BUT MY PROGRAM ABOVE STORES EVERY WORD AS A STRING...