There are two ways of comparison in Java. In you just want to match value of the string
Object.equals()
will be used. It simply compares the string values. While if you use == to compare, it will check the object reference. So
new String("test").equals("test") // --> true
new String("test") == "test" // --> false , since they are not the same object
new String("test") == new String("test") // --> false, both point to different objects.
0 Comment(s)