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

I need some help with this problem.

I have to "Add an if statement to make the first one equal the second"

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("hello"));

2 Answers

michaelcodes
michaelcodes
5,604 Points

Hi there! to check for equality you can call the method called .equals, methods are called by putting a period between them and whatever it is you want to call the method on. Heres an example below:

String firstExample = "hello";
String secondExample = "hello";
if (firstExample.equals(secondExample)) {
//code to execute if the if statement is true
}

Also notice that for if statements we want to put a starting { and ending } after the "if". The code inside of these braces will execute only if the conditions true. In the case of this task we want to put the following code inside:

console.printf("first is equal to second");

Hope this helps, happy coding!

Thank you very much i was kinda confused.

michaelcodes
michaelcodes
5,604 Points

Glad I could help, feel free to reach out to the community when you're confused and we'll do our best to solve it.