String string1 = \"Hi there\";
String string2 = \"Hi\";
String string3 = \"Hi\";
System.out.println(string1.substring(0, string2.length()) == string2); //1
System.o
If you want to compare Strings, then you should use String.equals() (or String.equalsIgnoreCase()) method. Comparing by == tells you only if two references points to same object. And in your example that's it: string2 and string3 points to same instance of string "Hi" (why should Java create two exactly same strings given in compile-time)