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

Patrick Shushereba
Patrick Shushereba
10,911 Points

String Equality Exercise

I'm having trouble with this exercise. I'm not quite understanding what I'm doing wrong. The compiler is telling me that the strings aren't the same length.

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(firstExample, thirdExample)) {
  console.printf("first and third are the same ignoring case");
}

2 Answers

Hey Patrick,

When doing challenges that have more than 1 task, be sure to leave the data behind from the 1st task unless explicitly told to delete that data. Also, equalsIgnoreCase() takes only one argument, which is the string to compare to. You call equalsIgnoreCase() on firstExample and then compare it to thirdExample:

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

The method "equalsIgnoreCase()" only takes one parameter of type string. So your it would look something like "string1.equalsIgnoreCase(string2)". This compares string1 to string2. If you intend to code Java I highly recommend becoming familiar with the oracle java docs site here it will come in handy.