Hi Gautam,
I think there is one more confusion here. Please note that
String s1=Thread.currentThread().getName();
will give you the name of current
thread which is "
main" and not
Thread1 which i think you are assuming.
And regarding
== so it is should be used for comparing references and not the content and if you want to check for equality then
you should use
equals(Object anObject)method.
However you will notice that in some cases == returns correct result, which is again due to another concept known as String Pooling in Java. For e.g:-
Suppose you have 2 strings declared as,
String s1 = "testString";
String s2 = "testString";
In this case s1==s2 will return true and which is because of String Pooling.
But i would say the best practice to check for equality should be using
public boolean equals(Object anObject) method.