Can you please tell me what is wrong with the following java code.
I am trying to collect input from the user through Scanner class object then store it in an array by using while but it would be infinite loop if i don't supply a break condition , so i thought to break when the input equals "q", but it didn't work.
import java.util.*;
public class ProjectOne{
public static void main (String []arg){
ArrayList one = new ArrayList();
Scanner input = new Scanner(System.in);
System.out.println("Enter");
String x = input.next();
while ( input.hasNext()){
if (x !="q"){
one.add(input);
}
if (x == "q")
{
break;
}
System.out.println(one);
}
}
}