1Case1)
2String s1 = "Stack Overflow";
3String s2 = "Stack Overflow";
4s1 == s1; // true
5s1.equals(s2); // true
6Reason: String literals created without null are stored in the string pool in the permgen area of the heap. So both s1 and s2 point to the same object in the pool.
7Case2)
8String s1 = new String("Stack Overflow");
9String s2 = new String("Stack Overflow");
10s1 == s2; // false
11s1.equals(s2); // true
12Reason: If you create a String object using the `new` keyword a separate space is allocated to it on the heap.
1compareTo() when you need to know the difference in length between strings
2that start with the same sequence of characters.
3
4 System.out.println("sumit".compareTo("timus"));//-1