what is difference betwn String st1="st"; and String st2=new("st"); i was try to compare with == but st1==st2 do not point to same object what is mean by string object created at runtime and compile time
If you only want to know if two strings are the same, use String.equals(), which returns a boolean. String.compareTo() does a lexigraphical comparison ( which is more costly) and returns an int signifying the lexical ordering (which is zero when the compared strings are equal according to the String.equals() method)
Use the '==' comparison operator when you want to know if two reference variables "point" to the same object.
String literals are created at compile time (in a special area of memory) so that the same literal strings point to the same String object.
Using the new operator creates a new String object at runtime (on the heap) which is not the same object as the same sequence of characters created at compile time.
Here "same object" generally speaking means a reference to the same location in memory.