Sunday, 8 January 2017

java - Why program will print "true" "true"?


Possible Duplicate:
Why are these == but not `equals()`?







why this code will print



true



true



public class Test {
public static void main(String[] args){
String st1 = "abc";
String st2 = "abc";


Integer k1 = 100;
Integer k2 = 100;

System.out.println(st1 == st2);
System.out.println(k1 == k2);
}
}



To compare objects we use method equals(). But why it is ok in this way?

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...