Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Basics Perfecting the Prototype String Equality

I need help understanding the question

Add another if statement that checks if the firstExample is equal ignoring case to thirdExample. If it, is print out "first and third are the same ignoring case".

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

I don't think I understand what exactly is being asked of me. Can someone break down the question for me?

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Dorian Ellison! Looks like you're doing pretty well! The challenge is asking for you to compare the first example against the third example and print out something if they are equal if you disregard the case. For example, if I don't take capitalization into account then "Tree", "tREE", "TREE", and "tree" should all be the same word.

To do this, you need the equalsIgnoreCase method. It was introduced in the previous video around the 3:58 mark.

if(firstExample.equalsIgnoreCase(thirdExample)) {
   // print your message here
}

Hope this helps! :sparkles: