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

Adan Huerta
Adan Huerta
3,209 Points

if Statements

I can't seem to figure out how to code this properly. What am I missing?

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

2 Answers

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi Adan,

remove " " from the statement:

  if (firstExample.equals ("secondExample")) 

And move the corrected if statement under the String declarations. The compiler goes from top to bottom and canΒ΄t see other Strings you are comparing to

Adan Huerta
Adan Huerta
3,209 Points

Thank you again Grigorij! It was the positioning that and "s that I was misplacing.

Gonna have to hire you as a proof checker bro. :D

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

LOL !!!!

See you in the forum .... and we can hit some errors :))))