Hi guys,
thanks for reading my post.
I am trying to store a user input of string into the arraylist and after storing all the user string input in the arraylist. i would like to print the content of each string index in the arraylist. Any advice would be appreciated.
import java.util.Scanner;
import java.util.ArrayList;
public class EchoStrings{
public static void main (String[] args){
ArrayList<String> stringList = new ArrayList<String>();// arraylist of string
String str = "start";//starting condition to make while loop run
Scanner kb = new Scanner(System.in);
do {
System.out.println("enter string:");
str=kb.next();
stringList.add(str);
}while(!str.equals("stop"));
for (int j =0;j<stringList.size();j++){
System.out.println(stringList.get(j));
}
}
}
my programs can compile but it just cant continue after the while loops it stops at the do while loop. Any advice is much appreciated. Thank You