title: How to fix a string input that give the wrong output?
body: <p>I have compiled and ran the code. It works but it's not giving me the  correct output.</p>
  
  <p>I should get when the user types Kelly, it should say "Names accepted". However, it says " names not accepted. Can somebody help me?</p>
  
  <pre><code>package compare;
  
  import java.util.Scanner;
  
  public class Democompare{
  
      public static void main(String[] args) {
  
          System.out.println("Try a match!");
          korean();
      }
  
      public static void korean()
      {
          String [] names1 = {"Kelly"};
          @SuppressWarnings("resource")
              Scanner sc = new Scanner(System.in);
          System.out.println("Input your answer:");
          String  ans1 = sc.nextLine();
          if(ans1 == names1[0])
          {
              System.out.println("Names accepted!");
          }
  
          else if(ans1 != names1[0]){
              System.out.println("Names not accepted!");
  
          }
      }
  }
  </code></pre>