When printing out the user input as indvidual words within a line I get a printout of all the words in that line.
System.out.println(userInput.next());
However, when I add the indvidual words to an ArrayList I appear to be getting random words back:
al.add(userInput.next());
Could someone explain to me what's going on?
Thanks.
This is a full copy of the code:
import java.util.*;
public class Kwic {
public static void main(String args[]){
Scanner userInput = new Scanner(System.in);
ArrayList<String> al = new ArrayList<String>();
while(userInput.hasNext()){
al.add(userInput.next());
System.out.println(userInput.next());
}
}
}