I want to create an Arraylist that holds strings as the user inputs them:
System.out.println("How many words do you want to enter?");
int numVerbs = scan.nextInt();
ArrayList <String> verbs = new ArrayList <String> (numVerbs);
System.out.println("Start entering words:");
for(int i=0;i<=numVerbs;i++){
verbs.add(scan.nextLine());
}
System.out.print(verbs.size());
}
The problem is that when I create and add the strings to the list, and then print out the size of the arraylist, it's one element larger than I want it to be.
For example, I'll enter 3 as how many words I want to add, then I'll input 3 words. However, when I print back the size of the arraylist it's 4 - not 3.
Maybe it has something to do with the verbs.add to an empty list? Idk, I'm at a loss.