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

To Lower Case

I"m not sure what I need to type to make it ignore case

I got the following error

JavaTester.java:80: error: no suitable method found for toLowerCase(String) } else if (firstExample == String.toLowerCase(thirdExample)){ ^ method String.toLowerCase() is not applicable (actual and formal argument lists differ in length) method String.toLowerCase(Locale) is not applicable (actual argument String cannot be converted to Locale by method invocation conversion) 1 error

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 == secondExample){
  console.printf("first is equal to second");
} elif (firstExample == String.toLowerCase(thirdExample)){
  console.printf("first and third are the same ignoring case");
}

1 Answer

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Jami;

In Java for String comparison:

== tests for reference equality (are two strings the same object).

.equals() tests for value equality.

To test if two string have the same value you would use firstString.equals(secondString). There is also an equalsIgnoreCase() method which may be of use for you in this challenge.

Happy coding,

Ken