Java Java Basics Perfecting the Prototype String Equality

Why can't I compare in this situation?

// I have imported a java.io.Console for you, it is named console. String firstExample = "hello"; String secondExample = "hello"; String thirdExample = "HELLO"; if(firstExample=secondExample){ console.printf("first is equal to second"); System.exit(0); }

Equality.java
// I have imported a java.io.Console for you, it is named console. 
String firstExample = "hello";
String secondExample = "hello";
String thirdExample = "HELLO";
if(firstExample=secondExample){
  console.printf("first is equal to second");
  System.exit(0);
}

1 Answer

Josh Keenan
Josh Keenan
17,329 Points

you can just remove the System.exit(0); and make sure you are testing for equality, you have used = instead of the comparison operator ==