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!

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

firstExample equal to secondExample - The "equals" method doesn't seem to be working for me. Anyone?

I am stuck on an exercise that requires me to set two strings equal to one another. In the video tutorial, this concept was demonstrated as a String relating to an integer value. (age < 13) But this is asking for two Strings to be set equal.

I've tried if (a.equals(b)) //---ERROR here// { if (a.equals("b")) //---ERROR here// { if (a ==("b"))... etc.

(a and b are used arbitrarily)

I'm not sure where I left off when I hit the Help button, so my code may look blatantly incomplete, but it is because I'd been trying and deleting different syntax for a good while...

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

1 Answer

Harry James
Harry James
14,780 Points

Hey Evan!

I've just tried the code you've provided on the first challenge and it passes for me.

Could you try refreshing the page and entering the code again? That might fix your problem.

Hope it helps but if you're still having problems, give me a shout :)

I left my machine sitting for almost half an hour with the browser window open. I think that messed it up. Just reloaded the exercise and it works now.

I'd deleted a bracket (codeblock) at one point, and that might have been what messed up my earlier attempts.

I declare permission for any moderators to delete this question if they do not feel it is helpful.

Harry James
Harry James
14,780 Points

Glad to hear you got it fixed and I'm keeping the post here don't worry!

Any question whether it's small or big, I love helping out where possible :)

Keep on posting and hope to see you around more in the future :D