Does the assignment operator consume memory in Java?

Viewed 1690

I have some two Strings as below:

"yes", "no".

Now, I would like to compare these Strings in two ways:

  1. Directly:
    Example: "yes".equals("no")

  2. By assigning the strings to some variable: Example:

    String string1 = "yes";
    String string2 ="no";
    string1.equals(string2);
    

In these two cases, is there any memory or performance difference?

3 Answers
Related