Hi,
I have done this code to learn ArrayList. I keep getting errors. Basically I want to accumulate names in list and when user types 'n' at prompt, it prints out names. What is wrong?
package mtangoo;
import java.util.ArrayList;
import java.util.Scanner;
public class MainClass {
public static void main(String args[]){
Listed jobject = new Listed();
}
Listed lst = new Listed();
}
class Listed{
Scanner getValues = new Scanner(System.in);
ArrayList<String> peopleList = new ArrayList<String>();
//looping
while (true){
System.out.println("Please Enter the Name:");
String name = getValues.nextLine();
peopleList.add(name);
System.out.println("Continue? y/n");
if(getValues.nextLine()=="n"){
break;
}//endif
else{
continue;
}
}
//loop finished
for(int i = 0; i<peopleList.size();i++){
System.out.println(peopleList.get(i));
}
}