title: Stop scanner from reading user input java?
body: <p>I am trying to write this method, which keeps reading from the user, until the word "exit" is inputted. I tried with a break and for loop; it didn't work. I was trying with while, but it does not stop even when the word "exit" is inputted. Any ideas how to fix this? Thanks.</p>
  
  <pre><code>public void read(Scanner scanner){
  
  while(3&lt;4){
  String in = scanner.nextLine();
  Scanner scanner_2 = new Scanner(in);
  
  String name = null;
  
  if(scanner_2.hasNext()){
    //create and add the user to the user container class
    name = scanner_2.next();
    System.out.println(name);
  }
  
  if(name == exit)
  //stop or break the while loop
  }
  }
  </code></pre>