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
K W
3,736 PointsI'm a bit confused with this challenge
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".
i passed with : String firstExample = "hello"; String secondExample = "hello"; String thirdExample = "HELLO"; if(firstExample==secondExample);{ console.printf("first is equal to second"); if(firstExample==thirdExample); console.printf("first and third are the same ignoring case"); }
?????was i suppose to enter the >equalsIgnoreCase< somewhere in the variable code???
or if someone used a different code i'd love to see it
any help would be appreciated thanx
6 Answers
Kevin Goodwin
713 PointsString 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");
This is the proper way to do it to complete the challenge, Technically you could use == to compare two strings but STRING.equals(STRING2); is the better way to do it.
The STRING.equalsIgnoreCase(STRING2) is used to check if two strings are equal and it ignores the case sensitive format.
I hope this helps
Mark Halverson
5,749 PointsI keep getting a Bummer!
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".
String firstExample = "hello";
String secondExample = "hello";
String thirdExample = "HELLO";
if(firstExample.equalsIgnoreCase(thirdExample)) {
console.printf("first and third are the same ignoring case");
}
Rui Bi
29,853 PointsTechnically, you won't be able to compare Java Strings using ==.
In Java, Strings are objects, which must be compared using the .equals() method. In the case of String, there is the additional .equalsIgnoreCase() method as well, which ignores the case of the characters contained in the String.
There are two types of variables in Java: primitive types and object references.
The basic primitive types are: int, double, float, boolean, and char (there are a few others less used ones, like bigint, byte, bit). Only primitive types can be compared using ==. In the case of primitives, == compares to see if two variables hold the same value.
Just about everything else in Java, including Console and String, are objects. In the case of objects, == will actually compare to see if two variables refer to the same object. It does not compare the actual data compared within the objects.
For example, if you had: String a = "hi"; String b = a;
Then a == b would return true, since in that case b is actually a reference to the same object that a refers to.
However, if you had: String a = "hi"; String b= "hi";
Then a == b would return false, since a and b refer to two different String objects that just happen to store the same data.
In that case, we need to use the String object's equals() method to determine if the two String objects store the same data.
Kevin Goodwin
713 PointsThank you
Zach Thacker
2,089 Pointshey wanna chat?
Alina Sirbeanu
992 PointsString firstExample = "hello"; String secondExample = "hello"; String thirdExample = "HELLO";
if(firstExample.equalsIgnoreCase (thirdExample)) { console.printf("first and third are the same ignoring case."); }
Hey everybody, I have the same problem..it keep showed bummer.I pass already the first exercises but at the second keep telling me "Bummer! Make sure you are using "equalsIgnoreCase" on the firstExample variable and use console.printf"
Can anyone tell me why? Cause the way i see i dint make any mistake in the code.
K W
3,736 PointsAWESOME THANX I KNEW I DID SOMETHING WRONG
Zach Thacker
2,089 PointsQUIT YELLING AT ME
Charles Kelly
620 PointsThanks for the help :).
michael arauza
Android Development Techdegree Student 2,397 Pointsthank you
Muhammad Asif
Courses Plus Student 557 PointsString 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");
HIDAYATULLAH ARGHANDABI
21,059 PointsIt is better to add curly braces.
Kevin Goodwin
713 PointsKevin Goodwin
713 PointsIf you have any questions feel free to email me @ kgoodwin@greaterlowelltech.org