Question: I'm trying to compare a string and a character (after converting it to a string). The code is not working like I expect it to work.

```
package main;
import java.lang.Character;

public class Main {
    public static void main(String[] args) {
        char myChar = 'a';
        String myString = "a";
        if(myString == Character.toString(myChar)) {
            System.out.println("This SHOULD work! But it doesn't.");
        } else {
            System.out.println("This SHOULDN'T work! But it does.");
        }
    }
}

```

What am I doing wrong here?

Answer: 
For comparing equality of string ,We Use equals() Method. There are two ways of comparison in java. One is "==" operator and another "equals()" method . "==" compares the reference value of string object whereas equals() method is present in the java.lang.Object class. This method compares content of the string object. .

So in your case, its better to use .equals() instead if "==".
Do not use == operator to compare strings. While string literals embedded to source code can be compared with this operator, this approach does not work for string objects, you get dynamically.

It is because == compares references to objects, not the object values.

Use `String.equals()` method to compare strings objects.