Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Basics Perfecting the Prototype String Equality

andrew neves
andrew neves
3,055 Points

anybody have any idea what could be wrong here? have tried multiple times and just cant put my finger on the error

Looking for someone to point me in the right direction here not able to figure this one out for some reason. I have a feeling its a very minuscule mistake that im over looking.

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

String thirdExample = "HELLO";

1 Answer

Nils Kriedner
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Nils Kriedner
Full Stack JavaScript Techdegree Graduate 30,933 Points

Hi Andrew,

it looks like when you write

firsExample.equals("secondExample")

you are actually comparing the firstExample VARIABLE with the STRING "secondExampleVariable" (not with the secondExample VARIABLE. Means you are checking wether the string "hello" equals the string "secondExample" - which are not equal.

So you might just have to delete those quotation marks.

Does that make sense?

I am asking because I actually don't know Java at all, but this could easily be the solution - as you wrote it's usually these tiny things... ;-)