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

Rahul Sharma
Rahul Sharma
402 Points

Usage: equalsIgnoreCase?

In the following code:

String firstExample = "hello"; String secondExample = "hello"; String thirdExample = "HELLO";

// This works if (firstExample.equals(secondExample)){ console.printf("first is equal to second"); }

// This does not work if (firstExample.equalsIgnoreCase(thirdExample)){ console.printf("first and the third are same ignoring case");

}

Here is the response I am receiving: Make sure you are using equalsIgnoreCase on the firstExample variable and use console.printf

Any ideas what I might be missing?

4 Answers

Ah okay, that's a bit strange. I've pasted my accepted solution below if you'd like to compare it with yours:

// 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");
}

if (firstExample.equalsIgnoreCase(thirdExample)) {
  console.printf("first and third are the same ignoring case");
}

Cool. I think part 2 expects both if statements to exist. Glad it works!

The below code should work. Make sure you match the exact output they are expecting including the word "the".

if (firstExample.equalsIgnoreCase(thirdExample)) {
    console.printf("first and third are the same ignoring case");
}
Rahul Sharma
Rahul Sharma
402 Points

Thank you for answering. I tried the edit but that didn't work either. Still the same error. Do you see anything else that might be wrong?

Rahul Sharma
Rahul Sharma
402 Points

This was part two of a set of two questions. I was deleting my code for task one when solving for task two. I went ahead and let both stay, it worked, I have no idea why. Guess I will figure that out as I go :')

Thanks a ton!