title: '==' does not work while checking string values, but '.equals()'does. Can anyone tell me why?
body: <p>import java.util.Scanner;
  public class RandomTest {</p>
  
  <pre><code>public static void main(String[] args) {
      Scanner input=new Scanner(System.in);
      String[] alphabets={"a","b"};
      String [] cipher={"b","c"};
      System.out.println("Please enter a letter.");
                  String word=input.nextLine();
  
      for (int i=0;i&lt;2;i++){
          if (word.equals(alphabets[i])){
              System.out.println("Preparing a cipher");
              System.out.println("Here is the cipher: "+cipher[i]);
  
              }
      }
  }
  }
  </code></pre>
  
  <p>This code above works perfectly fine, but instead of saying <code>(word.equals(alphabets[i]))</code>, if i put <code>word==alphabets[i]</code> it wouldn't work at all. While using the later, the program does not check if the input is equal to a value in the array. Why does this happen? </p>