String Comparison in a Little Detail
Why we avoid '==' operator to compare two strings We all know that we should use String class's equals method to compare two strings. When we use '==' operator to compare two equivalent String objects will give you 'false'. If those are String literal s then 'true'. The concern is you don't know whether the String reference is pointing to literal or String object. That's why you are always encouraged to use equals method to do string comparison. Let's check few examples with String literal those we are focusing on this article: 1 2 3 4 5 6 7 8 9 10 11 12 13 /** * Created by eananthaneshan on 6/8/16. */ public class Test { public static void main ( String [] args ) { String a = "a" ; String b = "b" ; String ab = "ab" ; System . out . println ( ab == ab ); System . out . println ( ab ==( a + b )); System . ou...