Why String concat(String) method is acting differently? : <p>I please check the code below.</p>

<p>I can understand that String s1 is not assigned and so even though concat(string) method is used it is giving the original output.</p>

<p>But also, in case of String s2 no variable is assigned but concatenation worked.</p>

<p>Can someone please explain?</p>

<pre><code>package com.stringconcat.main;

public class StringConcat {

    public static void main(String[] args) {

        String  s1 = "Hello";
        s1.concat(" World");
        System.out.println("String s1 output: " + s1);

        String s2 = "Hello" /*s1*/;
        System.out.println("String s2 output: " + s2.concat(" World"));
    }
}
</code></pre>

<p>The outputs are: 
String s1 output: Hello
String s2 output: Hello World</p>
