Having an issue with my do while loop as it doesn't end when STOP is entered. Also I'm not sure if I need to add any exceptions or what not. I know doing toString would be more efficient but the requirement for the program is a for loop when extracting the output.
import java.util.*;
import java.util.ArrayList;
import java.lang.IndexOutOfBoundsException;
public class MyProj
{
public static void main(String[] args)
{
ArrayList <String> MyItems = new ArrayList <String>();
Scanner Scan = new Scanner(System.in);
String Temp;
System.out.println("Please enter the name of an object, repeat as needed, type STOP to end");
do
{
Temp = Scan.nextLine();
if(Temp != "STOP")
{
MyItems.add(Temp);
}
}
while(Temp == "STOP");
for(int x = 0; x <= MyItems.size() - 1; x++)
{
System.out.println(MyItems.get(x));
}
}
}