I am writing a code that checks if String codon, a substring of String dna, is equal to "ATG". The code is as follows:
public class Test{
public void test() {
String dna = "ATGCTGTAG";
String codon = dna.substring(0,3);
System.out.println(codon); // should print ATG
System.out.println(codon == "ATG"); // should print true
}
public static void main(String[] args) {
Test t = new Test();
t.test();
}
}
However, when I run the quote, line 6 would print out false.
Another weird thing, when I changed a parameter of line 4:
String codon = dna.substring(0,9);
and line 6:
System.out.println(codon == "ATGCTGTAG"); line 6 would print out true.
I need to know if I need to change anything in my code to fix this bug.