Comparing strings in java
<pre><code>String string1 = "Hi there";
String string2 = "Hi";
String string3 = "Hi";

System.out.println(string1.substring(0, string2.length()) == string2); //1
System.out.println(string1.substring(0, string2.length()).equals(string2)); //2
System.out.println(string1.substring(0, string2.length()).compareTo(string2)); //3
System.out.println(string2 == string3); //4
System.out.println(string2.substring(0) == string3); //5
System.out.println(string2.substring(0) == string3.substring(0)); //6
</code></pre>

<p>Gives me the output:</p>

<pre><code>false
true
0
true
true
true
</code></pre>

<p>I don't really understand the first line, why does it give me false?</p>

<p>If I add a whitespace to string 2 and this line I get false, but if I add no whitespace I get true:</p>

<pre><code>System.out.println(string2.substring(0, string3.length()) == string3);
</code></pre>

<p>Why should line 1 give me false, but line 6 be true, but if I add a whitespace to string2 it's false..</p>

<p>Thanks =)</p>
