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

How do I add an if statement that checks to see if firstExample is equal to secondExample?

Do I keep the original if statement of equality or do I erase that to ask a new if statement of both Strings are equalsIgnoreCase.

Equality.java
// I have imported a java.io.Console for you, it is named console. 
String firstExample = "hello";
String secondExample = "hello";
String thirdExample = "HELLO";
if (firstExample.equalsIgnoreCase("thirdExample"))  
if (thirdExample.equalsIgnoreCase("firstExample"))      {
  console.printf("first and third are the same ignoring case. Exiting. ");
}
Mathew Tran
Mathew Tran
Courses Plus Student 10,205 Points

Note that thirdExample is not the same as "thirdExample"

"thirdExample" is a string literal thirdExample is a variable that holds the value of "HELLO"

Hope this makes sense!

Good Luck!

Matt

1 Answer

A Y
A Y
1,761 Points

Gerald,

(((if (firstExample == secondExample) console.printf("first is equal to second");)))

Please try: (((String firstExample = "hello"; String secondExample = "hello"; String thirdExample = "HELLO"; if (firstExample.equalsIgnoreCase(secondExample)) console.printf("first is equal to second");
if (thirdExample.equalsIgnoreCase(firstExample))
console.printf("first and third are the same ignoring case. Exiting.");))) It will work,

Amir